Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 每当我尝试运行编辑函数时,该函数都会执行,但文本不会附加到文件中 def EDIT(): 打印(“\n输入要编辑的文件”) command=input('\n$input_Python_Python 3.x - Fatal编程技术网

Python 每当我尝试运行编辑函数时,该函数都会执行,但文本不会附加到文件中 def EDIT(): 打印(“\n输入要编辑的文件”) command=input('\n$input

Python 每当我尝试运行编辑函数时,该函数都会执行,但文本不会附加到文件中 def EDIT(): 打印(“\n输入要编辑的文件”) command=input('\n$input,python,python-3.x,Python,Python 3.x,您需要关闭文件以刷新缓冲区 通常最好使用上下文管理器,以便自动关闭文件 def EDIT(): print("\nEnter the file you want to edit") command = input('\n$input<<') try: f = open(command + ".txt", "a") f.write(input('\n$append<

您需要关闭文件以刷新缓冲区

通常最好使用上下文管理器,以便自动关闭文件

 def EDIT():
    print("\nEnter the file you want to edit")
    command = input('\n$input<<')
    try:
        f = open(command + ".txt", "a")
        f.write(input('\n$append<<'))
    except FileNotFoundError:
        print('\nSorry, there was an error while trying to create your file. The file doesn\'t exist.\n')
    finally:
        NOTEPAD()
        
def EDIT():
打印(“\n输入要编辑的文件”)
command=input('\n$input请提供一个。
def EDIT():
    print("\nEnter the file you want to edit")
    command = input('\n$input<<')
    try:
        with open(command + ".txt", "a") as f:
            f.write(input('\n$append<<'))
    except FileNotFoundError:
        print('\nSorry, there was an error while trying to create your file. The file doesn\'t exist.\n')
    finally:
        NOTEPAD()