试图遍历一个文件夹。我正在研究 ipython3,在终端中打开。这是代码(在 python 3.6.4 中):
for filename in os.listdir('.'):
for file in filename:
with open(os.path.join('.',file), 'r') as f:
print(len(f))
但是我得到这个错误。
FileNotFoundError Traceback (most recent call last)
<ipython-input-6-1702c8aca957> in <module>()
1 for filename in os.listdir('.'):
2 for file in filename:
----> 3 with open(os.path.join('.',file), 'r') as f:
4 print(len(f))
5
FileNotFoundError: [Errno 2] No such file or directory: './d'
路径中添加了“d”,但找不到目录。Jupypter QtConsole 也是如此。