Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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 使用输入创建一个文件_Python_File_Input_With Statement_Getopenfilename - Fatal编程技术网

Python 使用输入创建一个文件

Python 使用输入创建一个文件,python,file,input,with-statement,getopenfilename,Python,File,Input,With Statement,Getopenfilename,我对打开的文件有问题。首先我需要设计我的文件名,然后它应该创建一个格式为.txt的块注释文件。此外,我必须使用%less来打印文件 这是我的代码: def file(): name=str(input("write the name of your file: ")) content=str(input("write : ")) with open(name+".txt" , &qu

我对打开的文件有问题。首先我需要设计我的文件名,然后它应该创建一个格式为.txt的块注释文件。此外,我必须使用%less来打印文件

这是我的代码:

    def file():
       name=str(input("write the name of your file: ")) 
       content=str(input("write : "))

       with open(name+".txt" , "w") as newfile:
         newfile.write(content)
       %less name.txt

    file()
    leer_libro("name.txt") #it counts my letters of each line

您必须使用在绝对路径上传递到
。
例如:

请输入一个绝对路径


你有这个问题吗?

你有什么问题?如果您回答
name
,代码应该可以工作。如果不够详细,代码就不能工作。如果您想使用普通的Unix工具,可能应该在文件末尾换行。
with open("D:/PYTHON/03_Coding_Rule/name.txt", "a") as fi: