Reputation: 6596
Using python cmd
module, I would like to be able to quit the command line application using Ctrl+D. However, default behavior prints ^D
instead of quitting the application.
Reading the documentation, I can't seem to find a way to do it. Any hints ?
Upvotes: 1
Views: 518
Reputation: 150031
From the doc:
An end-of-file on input is passed back as the string 'EOF'.
Which means that Ctrl+D is dispatched to the do_EOF()
method. So to give a way to exit your interpreter, make sure to implement do_EOF()
and have it return True
:
def do_EOF(self, line):
return True
Upvotes: 3