Idiomatic portable way to strip line endings?

Ulf Magnusson ulf.magnusson at ubm-computing.com
Sun Dec 16 10:56:27 EST 2001


> In general, I can use:
>
>     line = line[:-1]
> or
>     del line[-1:]

> snip...

> TIA,

There is an easy way to print them without the newline
print "hello world",

Use a comma attached at the end, this ofcourse doesn't modify the
string (strings are unmutable) but it fixes the print output.

the string module also supports the following
rstrip, strip, lstrip
which removes whitespaces (on the right side, the whole string, left side)

Cheers

/U. Magnusson






More information about the Python-list mailing list