comparison cmd2.py @ 236:035330ccfcf0

py really working right now
author catherine@dellzilla
date Tue, 24 Mar 2009 13:59:00 -0400
parents 78ad20c2eed0
children e91808980e59
comparison
equal deleted inserted replaced
235:78ad20c2eed0 236:035330ccfcf0
790 return 790 return
791 791
792 def do_py(self, arg): 792 def do_py(self, arg):
793 ''' 793 '''
794 py <command>: Executes a Python command. 794 py <command>: Executes a Python command.
795 py: Enters interactive Python mode; end with `Ctrl-D`. 795 py: Enters interactive Python mode; end with `Ctrl-D`, `quit()`, or 'exit`.
796 Do not end with Ctrl-Z, or it will end your entire cmd2 session!
797 Non-python commands can be issued with cmd('your non-python command here'). 796 Non-python commands can be issued with cmd('your non-python command here').
798 ''' 797 '''
799 if arg.strip(): 798 if arg.strip():
800 interp = InteractiveInterpreter(locals=self.pystate) 799 interp = InteractiveInterpreter(locals=self.pystate)
801 interp.runcode(arg) 800 interp.runcode(arg)
802 else: 801 else:
803 interp = MyInteractiveConsole(locals=self.pystate) 802 interp = MyInteractiveConsole(locals=self.pystate)
804 def quit(): 803 def quit():
805 raise EmbeddedConsoleExit 804 raise EmbeddedConsoleExit
805 def onecmd(arg):
806 return self.onecmd(arg + '\n')
806 self.pystate['quit'] = quit 807 self.pystate['quit'] = quit
807 self.pystate['exit'] = quit 808 self.pystate['exit'] = quit
808 self.pystate[self.nonpythoncommand] = self.onecmd 809 self.pystate[self.nonpythoncommand] = onecmd
809 try: 810 try:
810 interp.interact() 811 interp.interact()
811 except SystemExit: 812 except SystemExit:
812 quit() 813 quit()
813 except EmbeddedConsoleExit: 814 except EmbeddedConsoleExit: