1 #Encoding=utf-82 Importcmd3 ImportSYS4 5 6 #cmd module Exercises7 8 classClient (cmd. CMD):9 Ten " " One 1) cmdloop (): Similar to the Tkinter Mainloop, run the CMD parser; A 2) Onecmd (str): read input, and processing, usually do not need to overload the function, but use more specific do_command to perform a specific naming; - 3) Emptyline (): This method is called when an empty row is entered; - 4) Default (line): This method is called when an input command is not recognized; the 5) Completedefault (TEXT,LINE,BEGIDX,ENDIDX): If there is no complete_* () method on it, the function is called - 6) Precmd (line): command line parsing before the method is called; - 7) Postcmd (stop,line): command line is called after parsing the method; - 8) Preloop (): Cmdloop () call the method before running; + 9) Postloop (): Cmdloop () call the method after exiting; - + " " A at def __init__(self): -Cmd.cmd.__init__(self) -Self.prompt ='>' - - defDo_hello (Self, arg): - Print "Hello again", ARG,"!" in - defHelp_hello (self): to Print "Syntax:hello [message]", + Print "--Prints a Hello message" - the defdo_quit (Self, arg): *Sys.exit (1) $ Panax Notoginseng defHelp_quit (self): - Print "Syntax:quit", the Print "--Terminates the application" + #Shortcuts ADo_q =Do_quit theDo_eof =Do_quit + - if __name__=='__main__': $Client =Client () $Client.cmdloop ()#Cmdloop (): Similar to the Tkinter Mainloop, run the CMD parser;
Python cmd module exercises