python中io.open与open的区别

2024-05-16 10:24:18 发布

您现在位置:Python中文网/ 问答频道 /正文

在过去,有codecsio取代。尽管使用io.open似乎更为可取,但大多数介绍python的类仍然教open

有一个关于Difference between open and codecs.open in Python的问题,但是open仅仅是io.open的鸭子类型吗?

如果不是,为什么使用io.open更好?为什么用open教学更容易?

在本文(http://code.activestate.com/lists/python-list/681909/)中,Steven DAprano说内置的open在后端使用io.open。那么我们是否应该重构我们的代码以使用open而不是io.open

除了py2.x的向后兼容性之外,有没有理由在py3.0中使用io.open而不是open


Tags: andiniocomhttp类型codeopen
1条回答
网友
1楼 · 发布于 2024-05-16 10:24:18

根据文件,Python3号的情况:

io.open(file, *[options]*)

This is an alias for the builtin open() function.

以及

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

(粗体和斜体是我的编辑)

相关问题 更多 >