import sys import time import os poem=''' 测试读写文件 ''' print(os.getcwd()) f=file(os.getcwd()+'/python.txt','w') f.write(poem) f.close() C:UsersAdministratorDesktop Traceback (most recent call last): File "C:UsersAdministratorDesktoppythonTwo.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()