Skip to content

Instantly share code, notes, and snippets.

Created January 6, 2013 19:28
Show Gist options
  • Save anonymous/4469658 to your computer and use it in GitHub Desktop.
Save anonymous/4469658 to your computer and use it in GitHub Desktop.
Example of cmd.Cmd class
# 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()
@maxwillzq
Copy link

Cmd example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment