diff --git a/app/file_open.py b/app/file_open.py index 69d2f9d..b726ed5 100644 --- a/app/file_open.py +++ b/app/file_open.py @@ -23,8 +23,9 @@ class FileOpen: os.makedirs(my_dir) # 创建所有父文件夹 # 读文件需要判断文件是否存在,不存在则创建 if not os.path.exists(path): - open(path, mode, encoding) - return open(path, mode, encoding) + f = open(path, 'w', encoding) + f.close() + return open(path, mode=mode, encoding=encoding) @staticmethod def write_able(path, mode='w', encoding=None): @@ -33,7 +34,7 @@ class FileOpen: my_dir = os.path.dirname(path) # 获得路径的目录 if not os.path.exists(my_dir): # 判断文件的所有父文件夹是否存在 os.makedirs(my_dir) # 创建所有父文件夹 - return open(path, mode, encoding) + return open(path, mode=mode, encoding=encoding) if __name__ == "__main__":