help me debug my "word capitalizer" script

MRAB python at mrabarnett.plus.com
Wed Aug 22 11:40:34 EDT 2012


On 22/08/2012 09:20, Hans Mulder wrote:
[snip]
>
> Alternatively, if you want to remove only the line separator,
> you could do:
>
>          if line.endswith(linesep):
>              line = line[:-len(linesep)]
>
> The 'if' command is only necessary for the last line, which may or
> may not end in a linesep.  All earlier lines are guaranteed to end
> with a linesep.
>
Even better is:

     line = line.rstrip(linesep)

The line separator is '\n'.

Strictly speaking, the line separator varies according to platform
(Windows, *nix, etc), but it's translated to '\n' on reading from a
file which has been opened in text mode (the default).



More information about the Python-list mailing list