Some Python 2.1 ideas

Bob Alexander bobalex at home.com
Mon Dec 25 11:14:10 EST 2000


> I think in that case a function which does the "readline_chomp" is better:
> you don't need to change many object's declerations, mix them in, not
> to mention that it doesn't help built-in types at all. Frankly, I fail
> to see why people are so afraid of functions: generic functions *enhance*
> polymorphism.

As the person who started this "chomp" thread, I'd like to chime in that I
agree that having a family of "readline-without-the-newline" functions would
be good (e.g. counterparts for both readline and readlines). But having a
stand-alone chomper might still be good since Python program landscapes are
often littered with newline-terminated strings stored away in various
variables that need to be decontaminated later. It's a frequently-occurring
need to convert between newline-terminated and non-newline-terminated
strings.

readline_chomp would have to return something like None for end-of-file,
since empty lines would be valid data.

Finally, I'd be disappointed if the name "chomp" actually survived! I just
used it in my initial post as a placeholder until a better name came along,
since some folks would likely recall it from Perl. (If this were Java, we
could just call it removeTrailingNewLineCharacter(), but that's not very
Python-esque  :-)

Bob

P.S. Merry Christmas!





More information about the Python-list mailing list