python NameError: name 'file' is not defined

import sys
import time
import os poem='''\
测试读写文件
'''
print(os.getcwd())
f=file(os.getcwd()+'/python.txt','w')
f.write(poem)
f.close() C:\Users\Administrator\Desktop
Traceback (most recent call last):
File "C:\Users\Administrator\Desktop\pythonTwo.py", line , in <module>
f=file(os.getcwd()+'/python.txt','w')
NameError: name 'file' is not defined
[Finished in .2s with exit code ] 解决方法:file()改为open()
上一篇:pycharm python @符号不能识别 NameError: name 'app' is not defined


下一篇:python NameError: name 'raw_input' is not defined