-2
我似乎无法弄清楚如何从我的文本文件中删除单词“结束”。删除文件中的特定单词[Python 2.7.10]文件'object'没有属性删除
print "Max input for today is 30 links"
file = open("tutorials.txt", 'r+')
counter = + 1
while counter <= 30:
tutorial = raw_input("Enter Tutorial Link :")
file.write(str(tutorial) + '\n')
if tutorial == "end":
file.remove("end")
break
file.close()
当我运行该脚本,我得到这个回报:文件“对象”没有属性中删除
任何帮助表示赞赏:)
一旦输入是“end”,而不是将它写入文件? – timgeb
不知道我没有看到。非常感谢! – dexray
您应该考虑更改'文件'变量的名称,以免影响内置文件():https://docs.python.org/2/library/functions.html#file – n1c9