Created
January 4, 2019 17:02
-
-
Save AntaeusNar/1d715a2bef4b4563ad63725c83be2018 to your computer and use it in GitHub Desktop.
JSON file saving and reading
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 json | |
| def file_path_name_w_ext(file_name, path=None): | |
| if path is None: | |
| file_path = './' | |
| else: | |
| file_path = './' + path + '/' | |
| if file_name.endswith(".json"): | |
| path_name_w_ext = file_path + file_name | |
| else: | |
| path_name_w_ext = file_path + file_name + '.json' | |
| return path_name_w_ext | |
| def writeJSONfile(file_name, data, path=None): | |
| with open(file_path_name_w_ext(file_name, path), 'w') as fp: | |
| json.dump(data, fp) | |
| def getJSONfile(file_name, path=None): | |
| with open(file_path_name_w_ext(file_name, path), 'r') as fp: | |
| return json.load(fp) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment