Marienoelle Aminde
Marienoelle Aminde

Reputation: 1

how to fix FileNotFoundError Errno 2 no such file or directory

i have gone through some of the solutions provided but it doesn;t help me. Please someone tell me what im missing

from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os.path

bot = ChatBot('Cuibot') 
bot.set_trainer(ListTrainer)

for files in os.listdir('C:\\Users\\AMINDE64\\Chat\\chatterbot-corpus- 
1.1.2\\chatterbot_corpus\\data\\english'): 
data = open('C:\\Users\\AMINDE64\\chat\\chatterbot-corpus- 
1.1.2\\chatterbot_corpus\\data\\english' + files, "r").readlines()
bot.train(data)

while True:
    message = input('You:')
    if message.strip() != 'Bye':
    reply = bot.get_response(message)
               print('ChatBot :', reply) 
    if message.strip() == 'Bye':
    print('ChatBot : Bye')
   break

Upvotes: 0

Views: 4602

Answers (1)

zvone
zvone

Reputation: 19342

First, make the code a little bit more readable, e.g.:

dirname = 'C:\\Users\\AMINDE64\\Chat\\chatterbot-corpus- 
    1.1.2\\chatterbot_corpus\\data\\english'

for filename in os.listdir(dirname): 
    data = open(dirname + filename, "r").readlines()
    bot.train(data)

Now it is readable, but still doesn't work.

Then, use os.path.join to join the path, use with to make sure the file is propperly closed:

for filename in os.listdir(dirname): 
    with open(os.path.join(dirname, filename), "rt") as f:
        data = f.readlines()
    bot.train(data)

Upvotes: 1

Related Questions