我试图打开一个使用此代码的文件,但它又一次显示错误:NameError:name“practice”未定义 其中“practice”是我试图打开的文件。 “practice.txt”(即时试图打开的文件)存在于创建我的python程序的同一目录中。无法使用python打开文件
import os
name = input("Enter the name of the file : ")
if(os.path.exist(name)==True):
fopen = open(name,'w')
line = fopen.readline()
while(line != ""):
print(line)
line=fopen.readline()
fopen.close()
else:
print("file does not exist!!!")
是Python 2? – mentalita
根据你的错误信息,你应该使用'raw_input' – Wondercricket
python 2:'input'应该是'raw_input' –