make better save and load function of files and add snake config into a json file
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import os
|
||||
|
||||
def read_file(path, callback=None):
|
||||
if os.path.exists(path):
|
||||
with open(path, 'r') as f:
|
||||
data = callback(f)
|
||||
return data
|
||||
else:
|
||||
return None
|
||||
|
||||
def save_file(path, data, callback=None, *args, **kwargs):
|
||||
if not os.path.exists(path):
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
|
||||
with open(path, 'w') as f:
|
||||
callback(data, f, *args, **kwargs)
|
||||
Reference in New Issue
Block a user