How to implement key of key in python?

eckhleung at gmail.com eckhleung at gmail.com
Fri May 9 21:22:43 EDT 2014


I'm migrating from Perl to Python and unable to identify the equivalent of key of key concept. The following codes run well,

import csv                                                                       
                                
attr = {}                                                                        
                                                                                 
with open('test.txt','rb') as tsvin:                                           
    tsvin = csv.reader(tsvin, delimiter='\t')                                    
                                                                                 
    for row in tsvin:                                                            
        ID = row[1]                                                             


until:
        attr[ID]['adm3'] = row[2]  

I then try:
        attr[ID].adm3 = row[2]

still doesn't work. Some posts suggest using module dict but some do not. I'm a bit confused now. Any suggestions?



More information about the Python-list mailing list