Last active
August 29, 2015 14:15
-
-
Save phaustin/e1ea8a96e9f9615a618c to your computer and use it in GitHub Desktop.
json for config files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import io,json | |
| from collections import OrderedDict as od | |
| #need to add keys one at a time to preserve order | |
| key_order=[('ticket_db','tickets_2014.db'), | |
| ('ticket_info','2013_ticket_charges.csv'), | |
| ('ticket_history','ticket_history2014.csv'), | |
| ('amor_corrections','amor_corrections.json'), | |
| ('student','students.json')] | |
| name_dict=od() | |
| for key,value in key_order: | |
| name_dict[key] = value | |
| with io.open('names.json','w',encoding='utf8') as f: | |
| f.write(json.dumps(name_dict,indent=4,ensure_ascii=False,encoding='utf-8')) | |
| with io.open('names.json','r',encoding='utf8') as f: | |
| name_dict=json.loads(f.read(),object_pairs_hook=od) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment