擅长:python、mysql、java
<p>从链接的文档:</p>
<blockquote>
<p>Under Python 2.x, this is proposed as an alternative to the built-in file object</p>
</blockquote>
<p>所以它们在python2.x中是不一样的</p>
<p>至于第二部分,这在《Python2》和《Python3》中都很管用,虽然不是世界上最漂亮的东西:</p>
<pre><code>import io
try:
file_types = (file, io.IOBase)
except NameError:
file_types = (io.IOBase,)
with open("README.md", "r") as fin:
print(isinstance(fin, file_types))
</code></pre>