Last active
May 7, 2019 00:32
-
-
Save raganmd/1d63092e5eb834692c7675b73b513673 to your computer and use it in GitHub Desktop.
This file contains 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 json | |
def write_dict_to_json(target_file, dict_to_save): | |
''' | |
A Helper function that writes JSON file to disk | |
Args | |
--------------- | |
target_file (file path): | |
> a path to a .json file on disk. This is where the file will | |
> be written. | |
dict_to_save (dict): | |
> the dictionary to save as json. | |
Returns | |
--------------- | |
None | |
''' | |
# open the json file | |
json_file = open(target_file, 'w') | |
# ensure the format for the json is human readable | |
pretty_json = json.dumps(dict_to_save, indent=4) | |
# write the json to file | |
json_file.write(pretty_json) | |
# close the file | |
json_file.close() | |
# example use | |
target_file = '{}/cues.json'.format(project.folder) | |
target_dict = {"presets": op('base_example').fetch('presets')} | |
write_dict_to_json(target_file, target_dict) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment