17 lines
384 B
Python
17 lines
384 B
Python
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)
|