Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Jul 19, 2022

Conversation

tomaarsen
Copy link
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
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