How to get rid the new line

Emile van Sebille emile at fenx.com
Thu Jun 27 10:35:53 EDT 2002


"Markus von Ehr" <markus.vonehr at ipm.fhg.de> wrote in message
news:3D1AD534.A74EC9F4 at ipm.fhg.de...
>         f = open(filename, 'r')
>         lines = f.readlines()
>         line1 = lines[0] # exemplarily for first line
>         line1 = line1[0:len(line1)-1]
>
> or:
>         f = open(filename, 'r')
>         lines = f.readlines()
>         line1 = lines[0][0:len(line1)-1] # exemplarily for first line
>

Easier to strip the last character simply using [:-1]:

>>> s = 'this is a testX'
>>> s[:-1]

--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list