# encoding=utf-8
  import cmd
  import sys


  # cmd模块练习

  class Client(cmd.Cmd):

     '''
     1)cmdloop():类似与Tkinter的mainloop,运行Cmd解析器;
     2)onecmd(str):读取输入,并进行处理,通常不需要重载该函数,而是使用更加具体的do_command来执行特定的命名;
     3)emptyline():当输入空行时调用该方法;
     4)default(line):当无法识别输入的command时调用该方法;
     5)completedefault(text,line,begidx,endidx):如果不存在针对的complete_*()方法,那么会调用该函数
     6)precmd(line):命令line解析之前被调用该方法;
     7)postcmd(stop,line):命令line解析之后被调用该方法;
     8)preloop():cmdloop()运行之前调用该方法;
     9)postloop():cmdloop()退出之后调用该方法;

     '''

     def __init__(self):
         cmd.Cmd.__init__(self)
         self.prompt = '>'

     def do_hello(self, arg):
         print "hello again", arg, "!"

     def help_hello(self):
         print "syntax: hello [message]",
         print "-- prints a hello message"

     def do_quit(self, arg):
         sys.exit(1)

     def help_quit(self):
         print "syntax: quit",
         print "-- terminates the application"
         # shortcuts
     do_q = do_quit
     do_EOF = do_quit

 if __name__ == '__main__':
     client = Client()
     client.cmdloop()  # cmdloop():类似与Tkinter的mainloop,运行Cmd解析器;