本文共 650 字,大约阅读时间需要 2 分钟。
#!/usr/bin/pythonfrom cmd import Cmdimport osimport sysclass cli(Cmd): prompt ='tao>' intro = "welcom test" def __init(self): Cmd.__init__(self) def do_hello(self,args): print "hello",args def do_exit(self,args): print "exit" return True def default(self,args): print "pardon ?"if __name__ == '__main__': try: test=cli() test.cmdloop() except: exit()测试结果如下:tiantao@BoardServer2:~$ python cmd_test.pywelcom testtao>hellohellotao>hello taohello taotao>qwerpardon ?tao>exitexit
转载地址:http://bvnmi.baihongyu.com/