Skip to content

Instantly share code, notes, and snippets.

@phaustin
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save phaustin/e1ea8a96e9f9615a618c to your computer and use it in GitHub Desktop.

Select an option

Save phaustin/e1ea8a96e9f9615a618c to your computer and use it in GitHub Desktop.
json for config files
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