Python语言file和open区别是什么,python语言fileopen,Python里file(
Python语言file和open区别是什么,python语言fileopen,Python里file(
Python里file()和open()有什么区别?
现在自己知道的区别有file()不能创建文件,open()可以。
还有其他区别吗?
Python 2 里基本没区别。Python 3 里没 file。
Python 2 里,file 是文件对象。open 是返回新创建的文件对象的内建函数,相当于:
pythondef open(*args, **kwargs): return file(*args, **kwargs)
它真实的定义是:
cstatic PyObject *builtin_open(PyObject *self, PyObject *args, PyObject *kwds){ return PyObject_Call((PyObject*)&PyFile_Type, args, kwds);}
所以 file 也是能够创建文件的。
没有特别的区别吧, 查看他们的文档
>>> 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)
编橙之家文章,
相关内容
- python解释器问题,错误提示:0x80070652怎么办?,python0x8
- 网站迁移问题,django静态html目录url如何访问,djangourl,处
- python字符串嵌套与变量之间的问题,python嵌套,有没有类
- Python如何捕获微信摄推送服务端事件思路,python服务端
- python运行环境哪种轻巧又实用,python运行环境,在本机开
- 求问如下python解析库工作原理是什么,python工作原理
- Celery采用线程gevent并发模式启动具体方式是什么样的,
- Python做数据统计框架哪个好,python数据统计框架,如题。
- Python怎样实现在同一张图上画两次,python张图上画,如题
- Python支持调用其它语言函数吗?例如C++代码或Java包函数
评论关闭