nickjbyrne at gmail.com
Thu Jun 21 16:09:44 CEST 2007
On 21 Jun, 14:53, Neil Cerutti <horp... at yahoo.com> wrote:
> On 2007-06-21, Nick <nickjby... at gmail.com> wrote:
> > strip() isn't working as i expect, am i doing something wrong -
> > Sample data in file in.txt:
> > 'AF':'AFG':'004':'AFGHANISTAN':'Afghanistan'
> > 'AL':'ALB':'008':'ALBANIA':'Albania'
> > 'DZ':'DZA':'012':'ALGERIA':'Algeria'
> > 'AS':'ASM':'016':'AMERICAN SAMOA':'American Samoa'
> > Code:
> > f1 = open('in.txt', 'r')
> > for line in f1:
> > print line.rsplit(':').strip("'"),
> > Output:
> > Afghanistan'
> > Albania'
> > Algeria'
> > American Samoa'
> > Why is there a apostrophe still at the end?
> Most likely it's the newline at the end of each record that's
> getting in your way.
> You can double-strip it.
> for line in f1:
> print line.strip().rsplit(':').strip("'")
> Neil Cerutti
> The world is more like it is now than it ever has been before. --Dwight
Thank you all very much for your input, the above solved the problem
as most of you had already pointed out.
More information about the Python-list