Seeking assistance - string processing.
Fredrik Lundh
fredrik at pythonware.com
Tue Nov 14 06:31:23 EST 2006
billpaterson2006 at googlemail.com wrote:
> 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
> ===
that's probably because it *does* contain a newline. try printing the
line with
print repr(line)
before and after you make the change, to see what's going on.
> I tried fidding aruond trying to make it add whitespace but it didnt
> work.
peter's complete example contains one way to solve that:
if line.startswith("==="):
line = line.rstrip() + "===\n"
> What do you think I should do?
reading the chapter on strings in your favourite Python tutorial once
again might help, I think. python have plenty of powerful tools for
string processing, and most of them are quite easy to learn and use; a
quick read of the tutorial and a little more trial and error before
posting should be all you need.
</F>
More information about the Python-list
mailing list