在python 2.7中,我能够做到:
file('text.txt', 'w').write('some text')但是在python3中,我必须使用open函数,所以我不能再在一行上写入文件。
f = open('text.txt', 'w')
print('some text', file = f)
f.close()为什么他们要删除file函数?
发布于 2015-01-24 09:05:39
open('text.txt', 'w').write('some text')工作方式相同,很长一段时间以来,即使在Python2.x上,open也一直是打开文件(从而创建file实例)的规范方式。
https://stackoverflow.com/questions/28121163
复制相似问题