【发布时间】:2014-11-17 07:23:31
【问题描述】:
我正在使用 python 3.3.3。我正在做来自 tutorialspoint.com 的教程。我无法理解这个错误是什么。
这是我的代码:
fo = open("foo.txt", "w")
print ("Name of the file: ", fo.name)
# Assuming file has following 5 lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line
seq = ["This is 6th line\n", "This is 7th line"]
# Write sequence of lines at the end of the file.
fo.seek(0, 2)
line = fo.writelines( seq )
# Now read complete file from beginning.
fo.seek(0,0)
for index in range(7):
# line = fo.next()
print ("Line No %d - %s" % (index, line)+"\n")
# Close opend file
fo.close()
错误:
Name of the file: foo.txt
Traceback (most recent call last):
File "C:/Users/DELL/Desktop/python/s/fyp/filewrite.py", line 19, in <module>
line = fo.next()
AttributeError: '_io.TextIOWrapper' object has no attribute 'next'
【问题讨论】:
-
你的代码中真的有
# line = fo.next()被注释掉了吗? -
是的,当我不对此发表评论时,它给了我这个错误
标签: python