Skip to content

Use input() in nltk.chat.chatbot() for Jupyter support#3022

Merged
stevenbird merged 1 commit intonltk:developfrom
tomaarsen:bugfix/jupyter_chatbots
Jul 19, 2022
Merged

Use input() in nltk.chat.chatbot() for Jupyter support#3022
stevenbird merged 1 commit intonltk:developfrom
tomaarsen:bugfix/jupyter_chatbots

Conversation

@tomaarsen
Copy link
Copy Markdown
Member

Fixes #3021

Hello!

Pull request overview

  • Replace sys.stdin.readline() with input() in nltk.chat.chatbot()

Details

The following snippet is used to let users pick which of the 5 NLTK chatbots should be instantiated:

print("\nEnter a number in the range 1-%d: " % botcount, end=" ")
choice = sys.stdin.readline().strip()

However, the sys.stdin.readline() constantly triggers in such a way that choice is an empty string. This causes an endless loop, exactly as described in #3021:
image
Note that this is the output directly after running the cell. Be warned when testing this, this ended up crashing my computer due to the endless loop.


Changes

This PR simply updates this somewhat outdated form of getting user input by using the better supported input(). Running the cell now results in:
image
After which the chatbot works like intended & expected.

Thank you @jmcelroy01 for raising this issue.

  • Tom Aarsen

@tomaarsen tomaarsen changed the title Use input() instead of sys.stdin.readline(), as Jupyter supports the … Use input() in nltk.chat.chatbot() for Jupyter support Jul 19, 2022
@stevenbird stevenbird merged commit 4002af5 into nltk:develop Jul 19, 2022
@stevenbird
Copy link
Copy Markdown
Member

Thanks @tomaarsen

@tomaarsen tomaarsen deleted the bugfix/jupyter_chatbots branch July 19, 2022 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nltk.chat.chatbot() endless loop

2 participants