python: breaking a string into substrings using a for loop -


i have string this:

row='saint george 1739 1799 violin concerti g 029 039 050 symphonie concertante 2 violins g 024 bertrand cervera in 024 039 christophe guiot in 024 029 , thibault vieux violin soloists orchestre les archets de paris' 

i have loop:

for n in range (1,int(len(row)/55)+1): print row[(n-1)*55:n*55] 

it working well!!

however, cutting spaces:

saint george 1739 1799 violin concerti g 029 039 050 sy mphonie concertante 2 violins g 024 bertrand cerv era in 024 039 christophe guiot in 024 029 , thibault 

i not want cut spaces (however still want either 55 characters or less per line)

import textwrap  row='saint george 1739 1799 violin concerti g 029 039 050 symphonie concertante 2 violins g 024 bertrand cervera in 024 039 christophe guiot in 024 029 , thibault vieux violin soloists orchestre les archets de paris'  print(textwrap.fill(row,width=55)) # saint george 1739 1799 violin concerti g 029 039 050 # symphonie concertante 2 violins g 024 bertrand # cervera in 024 039 christophe guiot in 024 029 , # thibault vieux violin soloists orchestre les archets de # paris 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -