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 9, in <module> f=file(os.getcwd()+'/python.txt','w') NameError: name 'file' is not defined [Finished in 0.2s with exit code 1] 解决方法:file()改为open()