mirror of
https://github.com/hex-ci/smzdm_script.git
synced 2026-02-03 18:45:08 +08:00
update
This commit is contained in:
27
utils/file_helper.py
Normal file
27
utils/file_helper.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import toml
|
||||
|
||||
class TomlHelper:
|
||||
def __init__(self, toml_filename):
|
||||
self.t_dict = dict()
|
||||
self.toml_file_path = toml_filename
|
||||
|
||||
def update(self, t_data):
|
||||
self.t_dict.update(t_data)
|
||||
return self.t_dict
|
||||
|
||||
def write(self, t_data):
|
||||
with open(self.toml_file_path, "w", encoding="utf-8") as fs:
|
||||
toml.dump(t_data, fs)
|
||||
|
||||
def read(self):
|
||||
with open(self.toml_file_path, "r", encoding="utf-8") as fs:
|
||||
t_data = toml.load(fs)
|
||||
return t_data
|
||||
|
||||
def read_str(self, s_data):
|
||||
t_data = toml.loads(s_data, _dict=dict)
|
||||
return t_data
|
||||
|
||||
def read_dict(self, dict):
|
||||
t_data = toml.dumps(dict)
|
||||
return t_data
|
||||
Reference in New Issue
Block a user