Some Python 2.1 ideas

Greg Jorgensen gregj at
Sun Dec 24 01:34:03 CET 2000

"Bjorn Pettersen" <pbjorn at> wrote in message
news:3A452881.7686E717 at
> string.chomp() (a better name would be nice) needs to handle all of:
>  - "foo\n"
>  - "foo \n"
>  - "foo \r\n"
>  - "foo \n\r"
>  - "foo"
> 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>).

How should these be handled?



In other words, does the chomp() method always remove 0-2 characters, or all
trailing /n/r characters? Is it a good idea to add a string method that
makes assumptions about what the file.readline and file.readlines methods
return? Wouldn't it be cleaner to enhance the file object with additional

  f. readline_chomp()

Or perhaps add an attribute to the file object to indicate if newlines
should be stripped for text files?

  f.chomp = 1  # 1=strip trailing /n and /r characters, 0=leave them

Greg Jorgensen
Deschooling Society
Portland, Oregon, USA
gregj at

More information about the Python-list mailing list