make better save and load function of files and add snake config into a json file

This commit is contained in:
2024-04-12 11:16:49 +02:00
parent 33bcb09556
commit 664c374fbf
2 changed files with 29 additions and 11 deletions
+16
View File
@@ -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)