【发布时间】:2023-03-13 12:22:01
【问题描述】:
我对打开的文件有疑问。首先我需要设计我的文件的名称,然后它应该在格式为 .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 工具,你应该用换行符结束文件。
标签: python file input with-statement getopenfilename