[Tutor] rstrip in list?
sander.sweers at gmail.com
Tue Feb 9 16:56:38 CET 2010
On Tuesday 09 February 2010 16:28:43 Ken G. wrote:
> ['102\n', '231\n', '463\n', '487\n', '555\n', '961\n']
> I was using 'print mylist.rstrip()' to strip off the '\n'
> but kept getting an error of :
> AttributeError: 'list' object has no attribute 'rstrip'
A string has attribute rstrip not a list.
You will need to loop over the list and update each item of the list with
rstrip(). This, mylist = [s.rstrip('\n') for s in mylist], should do it.
It might be that before making the list you did rstrip() on the individual
More information about the Tutor