擅长:python、mysql、java
<p>更明确的方法检查<code>file</code>是否实际上是一个文件而不是目录,例如,它是可读的:</p>
<pre><code>from os import access, R_OK
from os.path import isfile
file = "/some/path/to/file"
assert isfile(file) and access(file, R_OK), \
"File {} doesn't exist or isn't readable".format(file)
</code></pre>