I read the answer to this question and still am getting the error AttributeError: 'dict' object has no attribute 'encode'
.
I've tried
dic = pickle.load(fileObject)
for v in dic:
v.encode('ascii', 'ignore')
and
dic = pickle.load(fileObject)
for key, val in dic.iteritems():
val.encode('ascii', 'ignore')
and still get the same error. When printing out the variables they all display with a u
at the front. The dictionary was pickled under python 3 and is being unpickled in python 2.
I tried pp.pprint((dataFromPrevMod).encode('ascii', 'ignore'))
and it didn't work.
If I pprint
out the dictionary, it shows its contents but in Python 3 each line starting with a u
for example u'website': u'exmample.org'
Dictionary pretty printed in Python 3
{
'output': {
'table': 'intersection',
'file_location': '\\\\storage1\\tpn\\tpn_team\\dev\\asmithe\\',
'schema': 'asmithe',
'temporary_location': '\\\\storage1\\tpn\\tpn_team\\dev\\asmithe\
\'
},
'tpn_inventory_db_r': {
'generic_pwd': '51f3tlNE26',
'db_name': 'tpn',
'user': 'asmithe',
'schema': 'asmithe',
'host': 'example.tpns.org'
},
'proj_year': '2005',
'proj_rules_r': 'C:\\asmithe\\rules.txt',
'incidents_db_r': {
'schema': 'tpn_pp_dist',
'generic_pwd': '51f3tlNE26',
'db_name': 'tpn',
'user': 'asmithe',
'fire_table': 'incident',
'host': 'example.tpns.org'
},
'plots_to_project_r': 'C:\\Users\\asmithe\\Plots.txt',
'tpn_proj_db_r': {
'generic_pwd': '51f3tlNE26',
'db_name': 'tpn inventory',
'user': 'asmithe',
'schema': 'test',
'host': 'example.tpns.org'
}
}
Dictionary pretty printed in Python 2 (notice the addition of u)
{ u'incidents_db_r': { u'db_name': u'tpn',
u'fire_table': u'incident',
u'generic_pwd': u'51f3tlNE26',
u'host': u'example.tpns.org',
u'schema': u'tpn_pp_dist',
u'user': u'asmithe'},
u'tpn_inventory_db_r': { u'db_name': u'tpn',
u'generic_pwd': u'51f3tlNE26',
u'host': u'example.tpns.org',
u'schema': u'asmithe',
u'user': u'asmithe'},
u'tpn_proj_db_r': { u'db_name': u'tpn inventory',
u'generic_pwd': u'51f3tlNE26',
u'host': u'example.tpns.org',
u'schema': u'test',
u'user': u'asmithe'},
u'output': { u'file_location': u'\\\\storage1\\tpn\\tpn_team\\dev\\asmithe\ \',
u'schema': u'asmithe',
u'table': u'intersection',
u'temporary_location': u'\\\\storage1\\tpn\\tpn_team\\dev\\asmithe idek\\'},
u'plots_to_project_r': u'C:\\Users\\asmithe\\Plots.txt',
u'proj_rules_r': u'C:\\asmithe\\rules.txt',
u'proj_year': u'2005'}