getting rid of EOL character ?
Steven Howe
howe.steven at gmail.com
Fri Apr 27 11:15:15 EDT 2007
stef wrote:
> hello,
>
> In the previous language I used,
> when reading a line by readline, the EOL character was removed.
>
> Now I'm reading a text-file with CR+LF at the end of each line,
> Datafile = open(filename,'r')
> line = Datafile.readline()
>
> now this gives an extra empty line
> print line
>
> and what I expect that should be correct, remove CR+LF,
> gives me one character too much removed
> print line[,-2]
>
> while this gives what I need ???
> print line[,-1]
>
> Is it correct that the 2 characters CR+LF are converted to 1 character ?
> Is there a more automatic way to remove the EOL from the string ?
>
> thanks,
> Stef Mientki
>
>>> abcd = 'abcdedff . \n'
>>> abcd
'abcdedff . \n'
>>> print abcd
abcdedff .
>>>* from string import strip*
>>> print abcd.strip()
abcdedff .
>>> a = abcd.strip()
>>> a
'abcdedff .'
>>>
sph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070427/43b3173b/attachment.html>
More information about the Python-list
mailing list