擅长:python、mysql、java
<p><a href="https://docs.python.org/2/library/os.html#os.listdir" rel="nofollow">^{<cd1>}</a>返回<code>directory</code>中的文件名列表。因此,除非<code>directory</code>是您当前的工作目录,否则您需要将这些文件名与实际目录连接起来,以获得正确的绝对路径:</p>
<pre><code>for filename in os.listdir(path):
filepath = os.path.join(path, filename)
f = open(filepath,'r')
raw = f.read()
# ...
</code></pre>