修复Windows读取文件编码错误!

This commit is contained in:
liyp 2022-05-07 10:02:34 +08:00
parent bf5cf254d8
commit e7c50aa484

View file

@ -87,7 +87,7 @@ def get_todo_list():
for root, dirs, files in os.walk(todo_path, topdown=False):
for name in files:
# print(os.path.join(root, name))
with open(os.path.join(root, name), 'r') as f:
with open(os.path.join(root, name), 'r', encoding='utf-8') as f:
# print(f.read())
json_file = json.load(f)
if json_file['itemType'] == 'ToDoList':
@ -108,7 +108,7 @@ def get_todo(todoListUid):
for root, dirs, files in os.walk(todo_path, topdown=False):
for name in files:
# print(os.path.join(root, name))
with open(os.path.join(root, name), 'r') as f:
with open(os.path.join(root, name), 'r', encoding='utf-8') as f:
# print(f.read())
json_file = json.load(f)
@ -133,7 +133,7 @@ def load_myday_important(item_type):
for root, dirs, files in os.walk(todo_path, topdown=False):
for name in files:
# print(os.path.join(root, name))
with open(os.path.join(root, name), 'r') as f:
with open(os.path.join(root, name), 'r', encoding='utf-8') as f:
# print(f.read())
json_file = json.load(f)
@ -165,7 +165,6 @@ def change_value(uid, key, value):
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
with open(todo_path + '{' + uid + '}.otl', 'r') as f:
json_file = json.load(f)
json_file[key] = value
@ -179,8 +178,7 @@ def load_value(uid, key):
config_path = return_work_dir()
todo_path = config_path + 'ToDoList/'
with open(todo_path + '{' + uid + '}.otl', 'r') as f:
with open(todo_path + '{' + uid + '}.otl', 'r', encoding='utf-8') as f:
json_file = json.load(f)
return json_file[key]
@ -196,7 +194,6 @@ def remove_todo_list(uid):
json_file = json.load(f)
if json_file['itemType'] == 'Todo' and json_file['todoListUid'] == uid:
os.remove(os.path.join(root, name))
@ -241,6 +238,7 @@ def check_login_status():
except TypeError as e:
return False
# print(read_init_file())
# webdav_hostname = read_init_file()
# print(webdav_hostname[2])