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
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
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
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'
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
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