Last active
December 24, 2018 07:13
-
-
Save Anton-Cao/d6ddfdeefa759f598f049ea3ba5d1088 to your computer and use it in GitHub Desktop.
Python script that copies new key-value pairs from sample_config.json to config.json
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
''' | |
Python script that copies new key-value pairs from sample_config.json to config.json | |
''' | |
import json | |
sample_file = open('sample_config.json', 'r') | |
sample_contents = json.loads(sample_file.read()) | |
sample_file.close() | |
try: | |
config_file = open('config.json', 'r') | |
config_contents = json.loads(config_file.read()) | |
config_file.close() | |
except: # file doesn't exist or is empty | |
config_contents = {} | |
for key, val in sample_contents.items(): | |
if key not in config_contents: | |
config_contents[key] = val | |
with open('config.json', 'w') as config_file: | |
json.dump(config_contents, config_file, indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment