line wrapping problem
Fuzzyman
fuzzyman at gmail.com
Thu Feb 9 07:06:42 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
>
You are using the print command to output the text to your file. This
will always put a '\n' at the end of lines (as well as your explicit)
one. The only time it doesn't do this is if the line ends with a
trailing comma, in which case it just adds a space.
The usual way is to write to yhour file object using :
mytextfile.write( mytextfile, "%s " % mydictionary[x],)
All the best,
Fuzzyman
http://www.voidspace.org.uk/python/index.shtml
>
> 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
More information about the Python-list
mailing list