On Sep 1, 9:41 am, Wojtek Walczak <[EMAIL PROTECTED]> wrote: > On Mon, 01 Sep 2008 15:25:03 +0200, Hans Müller wrote: > > I'm quite often using this construct: > > > for l in open("file", "r"): > > do something > > Has someone a better solution ? > > The most general would be to use rstrip() without > arguments: > > > > >>> a="some string\r\n" > >>> a.rstrip() > 'some string' > > but be careful, because it will also cut whitespaces: > > > > >>> a="some string\t \r\n" > >>> a.rstrip() > 'some string' > > so maybe you could do this: > > > > >>> a.rstrip('\n').rstrip('\r') > 'some string\t ' > > HTH. > > -- > Regards, > Wojtek Walczak,http://tosh.pl/gminick/
You can send both '\n' and '\r' in one rstrip call. No need for 2 separate calls. -- http://mail.python.org/mailman/listinfo/python-list