Python里file()和open()有什么区别?
现在自己知道的区别有file()不能创建文件,open()可以。
还有其他区别吗?
Python里file()和open()有什么区别?
现在自己知道的区别有file()不能创建文件,open()可以。
还有其他区别吗?
没有特别的区别吧, 查看他们的文档
>>> help(open)
open(...)
open(name[, mode[, buffering]]) -> file object
Open a file using the file() type, returns a file object. This is the
preferred way to open a file. See file.__doc__ for further information.
(END)
4 回答4.4k 阅读✓ 已解决
4 回答3.8k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
1 回答4.5k 阅读✓ 已解决
1 回答3.8k 阅读✓ 已解决
1 回答2.8k 阅读✓ 已解决
2 回答1.9k 阅读✓ 已解决
Python 2 里基本没区别。Python 3 里没
file
。Python 2 里,
file
是文件对象。open
是返回新创建的文件对象的内建函数,相当于:它真实的定义是:
所以
file
也是能够创建文件的。