io.open与在python中打开之间的区别 [英] Difference between io.open vs open in python
问题描述
过去,有codecs
被io
代替.尽管使用io.open
似乎更可取,但是大多数入门python类仍然讲授open
.
In the past, there's codecs
which got replaced by io
. Although it seems like it's more advisable to use io.open
, most introductory python classes still teaches open
.
Python中的open和codecs.open之间有区别,但是 open
仅仅是io.open
的鸭子类型吗?
There's a question with Difference between open and codecs.open in Python but is open
a mere duck-type of io.open
?
如果没有,为什么使用io.open
更好?为什么使用open
进行教学更容易?
If not, why is it better to use io.open
? And why is it easier to teach with open
?
在这篇文章中( http://code.activestate.com/lists/python -list/681909/),史蒂文·达普拉诺(Steven DAprano)说,内置的open
正在后端使用io.open
. 所以我们所有人都应该重构代码以使用open
而不是io.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. So should we all refactored our code to use open
instead of io.open
?
除了py2.x的向后兼容性之外,还有什么理由在py3.0中使用io.open
代替open
吗?
Other than backward compatibility for py2.x, are there any reason to use io.open
instead of open
in py3.0?
推荐答案
根据文档在Python3中的情况:
Situation in Python3 according to the docs:
io.open(file, *[options]*)
这是内置open()函数的别名.
This is an alias for the builtin open() function.
和
虽然内置的open()和关联的io模块是 推荐的方法,用于处理编码的文本文件,此模块 [即编解码器] 提供了其他实用工具功能和类, 在使用二进制文件时,允许使用范围更广的编解码器 文件
While the builtin open() and the associated io module are the recommended approach for working with encoded text files, this module [i.e. codecs] provides additional utility functions and classes that allow the use of a wider range of codecs when working with binary files
(粗体和斜体是我的修改)
(bold and italics are my edits)
这篇关于io.open与在python中打开之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!