擅长:python、mysql、java
<p>值得一提的是,“Not a directory”错误的一般含义是什么(Errno 20)。这意味着您试图使用的路径的子路径是一个真正的文件,而不是一个目录。这是一个格式错误的路径。</p>
<p>示例:file.txt/test.txt,其中file.txt是现有的真文件(不是目录)。</p>
<p>Python将为具有以下文件的每个I/O操作返回此错误:</p>
<pre><code>$ python -c 'import os; os.path.getsize("file.txt/test.txt");'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python2.7/genericpath.py", line 57, in getsize
return os.stat(filename).st_size
OSError: [Errno 20] Not a directory: 'file.txt/test.txt'
</code></pre>
<p>操作系统还将返回此错误:</p>
<pre><code>$ stat file.txt/test.txt
stat: cannot stat 'file.txt/test.txt': Not a directory
</code></pre>
<p>每次出现此错误,都意味着您将文件+文件连接到程序中的某个位置。</p>
<p>此错误是Unix操作系统特有的。在Windows上,对于这种格式错误的路径,您应该得到“找不到文件”。</p>