line wrapping problem
Peter Otten
__peter__ at web.de
Thu Feb 9 08:13:02 EST 2006
S Borg wrote:
> 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 # minimal fix
> 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)?
The trailing spaces are probably an artifact of your implementation. Here's
one way to avoid them:
print >> mytextfile, " ".join(str(mydictionary[x]) for x in myfoobar)
Peter
More information about the Python-list
mailing list