for featureline in ffeaturefile.readlines(): featureline = featureline.strip().split("|") addlist += "'%s', '%s'," % (featureline[0], featureline[3]) resfeaturelist = dict(addlist)for number, resline in enumerate(fresfile): resline = resline.strip().split("|") for count in [0, 21]: if (count == 21): #change values to text in features.txt resfields = resline[count].split(",") for i, item in enumerate(resfields): if (featureline[0] == item): print resfields[3] else: fsqlfile.write ("Insert into openrealty_en_listingsdbelements (listingdbelements_field_name,listingdbelements_field_value,listingsdb_id,userdb_id) values ('" + resheader[count] + "','" + resline[count] + "','" + str(number) + "','0');\n")Also, once I get the features.txt into a dictionary how do I do the substitution?
I'm not quite sure what you mean by substituion.. do you mean use the value instead of the key? Also, I'm wary of how you are creating your dictionary.
I propose the following modification to the first bit of code:
resfeaturelist = {}
for featureline in ffeaturefile.readlines():
featureline = featureline.strip().split("|")
addlist += "'%s', '%s'," % (featureline[0], featureline[3])
resfeaturelist[ featureline[0] ] = featureline[3] Now take a look at this example of working with a dictionary to see if it answers your question about "substitution":
>>> dd = {} # Initialize the dictionary
>>> dd[ '7801' ] = 'Heat Pump'
>>> dd[ '7902' ] = 'Central A/C'
>>> dd[ '8901' ] = 'Box Fan'
>>> print dd[ '7801' ]
Heat Pump
>>> "INSERT x into y VALUES( '%s', '%s', '0' );" % ( dd['7801'], dd['8901'] )
"INSERT x into y VALUES( 'Heat Pump', 'Box Fan', '0' );"
>>> dd.get( '7901' )
>>> dd.get( '7902' )
'Central A/C'
>>> As you can see there's two different methods to retrieving values from a dictionary. Using get() is safer since you can check if <value> == None: so that you don't get any code-stopping exceptions; however in your case you may want the code to stop.
Let me know whether this clears up your questions, and whether that first bit helped to alleviate your problems..