1. 程式人生 > >NameError: name 'file' is not defined

NameError: name 'file' is not defined

poem = '''Program is fun
when the work is done
if you wanna make your work also fun:
use python'''
f = file('poem.txt','w') # open for 'w'riting
f.write(poem) # write text to file
f.close() # close the file
f = file('poem.txt')

while True:
   line= f.readline()
   if len(line) == 0:
        break
print
(line) f.close()
執行結果:
經過排查錯誤發現:file改成open就好了