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()

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM