line wrapping problem

Juho Schultz juho.schultz at helsinki.fi
Thu Feb 9 07:16:37 EST 2006


S Borg wrote:
> Hello,
> 
>  I am parsing text from one document to another. I have a scheme
> similar to:
> 
>  for x in myfoobar:
>    print >> mytextfile, "%s    " % mydictionary[x],   #all on same line
>  print >> mytextfile, '\n'      #new line
> 
> 
> I am getting line breaks before my explicit line break. Am I
> unwittingly copying '\n' characters from the original file?
> How should I fix this(What is the 'Pythonic' solution)?
> 
> thanks,
> -S
> 

mytextfile.write("%s    " % mydictionary[x])

should work. IMO file.write() is self-explanatory but "print >> file" is 
a bit obscure.



More information about the Python-list mailing list