Re: Eleganz way to get rid of \n

2008-09-01 Thread Fredrik Lundh
Hans Müller wrote: I'm quite often using this construct: for l in open("file", "r"): do something here, l contains the \n or \r\n on windows at the end. nope -- if you open a file in text mode (without the "b"), the I/O layer will translate "\r\n" to "\n" on Windows. if you want even

Re: Eleganz way to get rid of \n

2008-09-01 Thread Bruno Desthuilliers
Hans Müller a écrit : Hello, I'm quite often using this construct: for l in open("file", "r"): do something here, l contains the \n or \r\n on windows at the end. I get rid of it this way: for l in open("file", "r"): while l[-1] in "\r\n": l = l[:-1] I find this a little bit

Re: Eleganz way to get rid of \n

2008-09-01 Thread josh logan
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() wit

Re: Eleganz way to get rid of \n

2008-09-01 Thread Wojtek Walczak
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'

Re: Eleganz way to get rid of \n

2008-09-01 Thread josh logan
On Sep 1, 9:25 am, Hans Müller <[EMAIL PROTECTED]> wrote: > Hello, > > I'm quite often using this construct: > > for l in open("file", "r"): >         do something > > here, l contains the \n or \r\n on windows at the end. > I get rid of it this way: > > for l in open("file", "r"): >         while

Eleganz way to get rid of \n

2008-09-01 Thread Hans Müller
Hello, I'm quite often using this construct: for l in open("file", "r"): do something here, l contains the \n or \r\n on windows at the end. I get rid of it this way: for l in open("file", "r"): while l[-1] in "\r\n": l = l[:-1] I find this a little bit clumsy