擅长:python、mysql、java
<p>对于Python2</p>
<pre><code>import types
f = open('test.txt', 'r') # assuming this file exists
print (isinstance(f,types.FileType))
</code></pre>
<p>对于Python3</p>
^{pr2}$
<p>(编辑:我以前的解决方案测试io.TextIOWrapper,它只适用于以文本模式打开的文件。请参见描述python3类层次结构的<a href="https://docs.python.org/3/library/io.html#class-hierarchy" rel="nofollow">https://docs.python.org/3/library/io.html#class-hierarchy</a>)。在</p>