python - How to exit the cmd loop of cmd module cleanly -


However, with this documentation: It is not clear what is a clear way to get out of the program (i.e. CMDLop) programmatically

Ideally, at some command exit prompt, I will exit the program.

You must override the postcmd method:

CMD. Postcmd (stop, line)

Hook method executed immediately after the expiration of the command dispatch. This method is a stub in CMD; It is overridden by subwalse line command line that was executed, and the stop is a flag that indicates whether postcmd () will be aborted after execution call; This return value of the ACMD () method will be used to return the value of this method as the new value of the internal flag, which matches to stop; The interpretation continues because of the wrong return.

and cmdloop from the document:

This method will return when the postcmd () method returns a true value postcmd () Is the return value of the do_ * () method related to the stop arbikar command ATAC.

In other words:

  Import the CMD Class Test (CMD. CMD): # Your stuff (do_XXX methods should do nothing or wrong ) Def do_exit (auto, * args): return True    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -