Hi Team,
I am trying to convert one text file in dictionary but it remains empty . Please help .
text files sample records are as follows
CC_FIPS FULL_NAME_ND
AN Aixas
AN Aixirivall
AN Aixovall
AN Andorra la Vella
AN Ansalonga
AN Anyos
AN Arans
AN Arinsal
AN Aubinya
AN Bixessarri
There is tabsapce between column as per my understading
I am trying to convert one text file in dictionary but it remains empty . Please help .
text files sample records are as follows
CC_FIPS FULL_NAME_ND
AN Aixas
AN Aixirivall
AN Aixovall
AN Andorra la Vella
AN Ansalonga
AN Anyos
AN Arans
AN Arinsal
AN Aubinya
AN Bixessarri
There is tabsapce between column as per my understading
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
import json filename = 'C:/Users/pubhatia/Documents/learning/python/query/GEODATASOURCE-CITIES.TXT' #creating states dictionary object states = {} with open (filename) as fh: for line in fh: line = line.split( ' ' ) if not line: # empty line? print (line) continue states[line[ 0 ]] = line[ 1 :] if not bool (states): print ( 'Dict is Empty' ) |
Output:['AF', 'Biland\n']
['\n']
['AF', 'Biland Hawa\n']
Dict is Empty