Created
          January 6, 2013 19:28 
        
      - 
      
 - 
        
Save anonymous/4469658 to your computer and use it in GitHub Desktop.  
    Example of cmd.Cmd class
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # file test.py | |
| import cmd | |
| class HelloWorld(cmd.Cmd): | |
| def do_greet(self,person=''): | |
| print "hello,",person | |
| def help_greet(self): | |
| print '\n'.join(['greet [person]', | |
| 'greet the named person', | |
| ]) | |
| def complete_greet(self,text,line,begidx,endix): | |
| friends = ['harry','roger','erica'] | |
| if not text: | |
| return friends | |
| else: | |
| return [f for f in friends | |
| if f.startswith(text)] | |
| def do_EOF(self,line): | |
| return True | |
| def do_quit(self,line): | |
| print "quit" | |
| return True | |
| if __name__ == '__main__': | |
| HelloWorld().cmdloop() | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Cmd example