In the beginning I create xls_dict
and xml_dict
Then wrapped the above 2 dicts into dictionary's creation. (I though it is copy be reference)
So I will load the json files into the 2 dicts.
However, I found when I exit the
for export_file, data_dict in json_files.iteritems():
block.
the xls_dict
and xml_dict
are not changed.
The was not my expectation.
Where did I misunderstand ? Thanks
xls = MultiLangXls(xls_path, XLS_COLUMN)
xls_dict = xls.load()
xml = MultiLangXML(xml_path)
xml_dict = xml.load()
json_files={
"xls.json": xls_dict,
"xml.json": xml_dict
}
for export_file, data_dict in json_files.iteritems():
if os.path.isfile(export_file):
pass
else: # If json file not exists, then ouput the dict into json file
with open( export_file , 'w') as f:
json.dump(data_dict, f, encoding="utf-8")
load_file = open(export_file).read().decode("utf-8-sig")
data_dict = {}
data_dict = json.loads( load_file )