FileNotFoundError: [Errno 2] No such file or directory: 'englishcomputers.yml'

FileNotFoundError: [Errno 2] No such file or directory: 'englishcomputers.yml'

for files in os.listdir('english'):
data=open('english'+ files,'r').readlines()
bot.train(data)

打开文件的 for 循环的第一行产生错误。

我也更改了 "computers.yml" 文件,但它不起作用,因为它似乎没有正确获取路径。

请问有什么解决办法吗?

您需要包含 / 分隔目录和文件名,以便从 english 目录中的适当路径打开特定文件。

#!/usr/bin/env python

import os

for files in os.listdir('english'):
    file_path=os.path.join('english',files)
    data=open(file_path,'r').readlines()
    bot.train(data)