On Dec 12, 10:31 am, "Rhodri James" <[email protected]>
wrote:
> On Thu, 11 Dec 2008 19:49:23 -0000, Steve Holden <[email protected]>
> wrote:
>
>
>
> > Kirk Strauser wrote:
> >> At 2008-11-29T04:02:11Z, Mel <[email protected]> writes:
>
> >>> You could try
>
> >>> for item in fname:
> >>> item = item.strip()
>
> >> This is one case where I really miss Perl's "chomp" function. It
> >> removes a
> >> trailing newline and nothing else, so you don't have to worry about
> >> losing
> >> leading or trailing spaces if those are important to you.
>
> > ... and it's so hard to write
>
> > item = item[:-1]
>
> Tsk. That would be "chop". "chomp" would be
>
> if item[-1] == '\n':
> item = item[:-1]
Better:
if item and item[-1] == '\n':
return item[:-1]
return item
--
http://mail.python.org/mailman/listinfo/python-list