strip() 2.4.4
Nick
nickjbyrne at gmail.com
Thu Jun 21 09:23:01 EDT 2007
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?
Thanks in advance.
Nick
More information about the Python-list
mailing list