From c14de06c863e744f0ff7bbe0f7f09e305f9572d5 Mon Sep 17 00:00:00 2001 From: torch <178428409@qq.com> Date: Tue, 22 Nov 2022 19:19:00 +0800 Subject: [PATCH] =?UTF-8?q?FileOpen=E5=B7=A5=E5=85=B7=E7=B1=BB=E5=AD=98?= =?UTF-8?q?=E5=9C=A8Bug=EF=BC=8C=E5=86=85=E9=83=A8=E6=8A=B5=E7=94=A8open?= =?UTF-8?q?=E5=87=BD=E6=95=B0=E7=9A=84=E6=97=B6=E5=80=99=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E5=8F=82=E6=95=B0=EF=BC=8C=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E7=B1=BB=E5=9E=8B=E4=B8=8D=E5=8C=B9=E9=85=8D?= =?UTF-8?q?=E3=80=82=E8=BF=99=E9=87=8C=E8=BF=9B=E8=A1=8C=E4=BA=86=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E7=9A=84=E6=8C=87=E5=AE=9A=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?Bug=E3=80=82=E5=90=8C=E6=97=B6=E5=AF=B9read=E6=97=B6=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8=EF=BC=8C=E5=88=9B=E9=80=A0?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E5=AD=98=E5=9C=A8=E7=9A=84=E9=9A=90=E8=97=8F?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E8=BF=9B=E8=A1=8C=E4=BA=86=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/file_open.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) 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__":