问题描述
我在打开文件时遇到问题。首先,我需要设计我的文件的名称,然后它应该在块注释中创建一个格式为 .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
解决方法
您必须将绝对路径传递给 with
。
示例:
with open("D:/PYTHON/03_Coding_Rule/name.txt","a") as fi:
请输入绝对路径
你有这个问题吗?