📜  如果文件不存在则创建一个文件 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:05.255000             🧑  作者: Mango

代码示例1
import os

file_path = r'E:\pynative\account\profit.txt'
if os.path.exists(file_path):
    print('file already exists')
else:
    # create a file
    with open(file_path, 'w') as fp:
        # uncomment if you want empty file
        fp.write('This is first line')