mirror of
https://github.com/myned/modufur.git
synced 2024-12-24 14:27:27 +00:00
Added json to setdefault helper method
This commit is contained in:
parent
a3d9ac81d9
commit
4d188e2a4a
1 changed files with 13 additions and 1 deletions
|
@ -36,7 +36,8 @@ except FileNotFoundError:
|
|||
'FILE NOT FOUND : config.json created with abstract values. Restart run.py with correct values')
|
||||
|
||||
|
||||
def setdefault(filename, default=None):
|
||||
def setdefault(filename, default=None, json=False):
|
||||
if not json:
|
||||
try:
|
||||
with open(filename, 'rb') as infile:
|
||||
print('LOADED : {}'.format(filename))
|
||||
|
@ -47,6 +48,17 @@ def setdefault(filename, default=None):
|
|||
pkl.dump(default, iofile)
|
||||
iofile.seek(0)
|
||||
return pkl.load(iofile)
|
||||
else:
|
||||
try:
|
||||
with open(filename, 'rb') as infile:
|
||||
print(f'LOADED : {filename}')
|
||||
return jsn.load(infile)
|
||||
except FileNotFoundError:
|
||||
with open(filename, 'wb+') as iofile:
|
||||
print(f'FILE NOT FOUND : {filename} created and loaded with default values')
|
||||
jsn.dump(default, iofile)
|
||||
iofile.seek(0)
|
||||
return jsn.load(iofile)
|
||||
|
||||
|
||||
def load(filename, *, json=False):
|
||||
|
|
Loading…
Reference in a new issue