On 21 Jun, 14:53, Neil Cerutti <[EMAIL PROTECTED]> wrote: > On 2007-06-21, Nick <[EMAIL PROTECTED]> 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(':')[4].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(':')[4].strip("'") > > -- > Neil Cerutti > The world is more like it is now than it ever has been before. --Dwight > Eisenhower
Thank you all very much for your input, the above solved the problem as most of you had already pointed out. -- http://mail.python.org/mailman/listinfo/python-list