[Tutor] Re: How to remove a newline character

Robert L. Oelschlaeger roelsch@acm.org
Sat, 6 Apr 2002 16:06:21 -0600


# Try: strip() from the string module:
#
# strip(s)
#Return a copy of s without leading or trailing whitespace.

MyList=['272580\n', '23232432\n']
print MyList

import string
MyList = map(string.strip, MyList)
print MyList

----- Original Message -----
From: "A" <printers@sendme.cz>
To: <python-help@python.org>; <activepython@listserv.activestate.com>;
<tutor@python.org>
Sent: Saturday, April 06, 2002 2:31 PM
Subject: How to remove a newline character


> Hi,
> Can you please let me know  if it is possible to replace
> new line characters( '\n') in a list in one step?
>
> I have list like
>
> MyList=['272580\n', '23232432\n']
>
> and I would like to have
> ,MyList=['272580', '23232432']
>
> so I tried
> re.sub('\n','',MyList)
> but I received
> TypeError: expected string or buffer
>
> Your help would be appreciated
> Thanks.
> Ladislav
>
> I look forward to hearing from you soon.
>
> Best Regards,
> Ladislav Blazek( Mr.)
>
> BMA TRADING Ltd.
> email: export@sendme.cz
> email2: export@bmatrading.com
> Fax:/Tel +420 506 447921
> Tel:+420 506 447920, +420 602 849309
>
>
> _______________________________________________
> ActivePython mailing list
> ActivePython@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs