Seeking assistance - string processing.
Peter Otten
__peter__ at web.de
Tue Nov 14 06:37:21 EST 2006
billpaterson2006 at googlemail.com wrote:
> Cheers for the reply.
>
> But I'm still having a spot of bother with the === addition
>
> it would seem that if there is no whitespace after the ===test
> then the new === gets added to the next line
>
> e.g file contains:
>
> ===test (and then no whitesapace/carriage returns or anything)
>
> and the result is:
>
> ===test
> ===
You'd get the above with Fredrik's solution if there is a newline. That's
why I put in the rstrip() method call (which removes trailing whitespace)
and added an explicit "\n" (the Python way to spell newline). With my
approach
if line.startswith("==="):
line = line.rstrip() + "===\n"
you should always get
===test===(and then a newline)
Peter
More information about the Python-list
mailing list