[英]Difference between io.open vs open in python
In the past, there's codecs
which got replaced by io
. 在过去,有些
codecs
被io
取代。 Although it seems like it's more advisable to use io.open
, most introductory python classes still teaches open
. 尽管使用
io.open
似乎更合适,但大多数入门级python类仍然可以open
。
There's a question with Difference between open and codecs.open in Python but is open
a mere duck-type of io.open
? 在Python中使用open和codecs.open之间的区别是一个问题,但它只是
open
了一种类型的io.open
?
If not, why is it better to use io.open
? 如果没有,为什么使用
io.open
会更好? And why is it easier to teach with open
? 为什么
open
教学更容易?
In this post ( http://code.activestate.com/lists/python-list/681909/ ), Steven DAprano says that the built in open
is using the io.open
in the backend. 在这篇文章中( http://code.activestate.com/lists/python-list/681909/),Steven DAprano说内置的
open
是在后端使用io.open
。 So should we all refactored our code to use open
instead of io.open
? 那么我们是否应该重构我们的代码以使用
open
而不是io.open
?
Other than backward compatibility for py2.x, are there any reason to use io.open
instead of open
in py3.0? 除了py2.x的向后兼容性之外,有没有理由在py3.0中使用
io.open
而不是open
?
Situation in Python3 according to the docs: 根据文档在Python3中的情况:
io.open(file, *[options]*)
This is an alias for the builtin open() function.
这是内置open()函数的别名。
and 和
While the builtin open() and the associated io module are the recommended approach for working with encoded text files, this module [ie codecs] provides additional utility functions and classes that allow the use of a wider range of codecs when working with binary files
虽然内置的open()和相关的io模块是处理编码文本文件的推荐方法 ,但是这个模块[即编解码器]提供了额外的实用程序功能和类,允许在使用二进制文件时使用更广泛的编解码器
(bold and italics are my edits) (粗体和斜体是我的编辑)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.