perl chomp equivalent in python?

Fred Gansevles gansevle at cs.utwente.nl
Wed Mar 8 16:33:48 CET 2000


Nathan Clegg wrote:

> On 10-Feb-2000 Will Ware wrote:
> > I often find myself doing things like this inside 'for
> > ...readlines():'
> > loops, and it always strikes me as cheesy and inelegant. It'd be
> > kinda
> > cool if readlines() could take an argument that meant to strip away
> > any trailing whitespace.
>
> Why not use string.rstrip() ???
>
> for line in map(string.rstrip, f.readlines()):
>         ....
>
> ----------------------------------
> Nathan Clegg
>  nathan at islanddata.com

I always use

    for line in string.split (open (file).read(), '\n'):
        ....





More information about the Python-list mailing list