Some Python 2.1 ideas

Tino Wildenhain tino at wildenhain.de
Sun Dec 24 05:27:26 EST 2000


Hi Bjoern,

Bjorn Pettersen wrote:
> 
> string.chomp() (a better name would be nice) needs to handle all of:
> 
>  - "foo\n"
>  - "foo \n"
>  - "foo \r\n"
>  - "foo \n\r"
>  - "foo"

In all cases I came across such a problem, string.replace() did its job.
replacing \n with '' and \r with '' looks a bit ugly but works perfectly
:-)

> 
> etc. correctly, which means it should delete between zero and two bytes
> (characters) from the end of the string. This is very different from
> removing leading or trailing whitespace (whitespace can be significant
> you know <wink>).

Regards
Tino




More information about the Python-list mailing list