Mercurial > python-cmd2
comparison cmd2.py @ 220:8c277a37e2bc
yay py works fully
author | catherine@Elli.myhome.westell.com |
---|---|
date | Wed, 18 Mar 2009 18:27:29 -0400 |
parents | 35be1f8332a9 |
children | 9aa1f34455b4 |
comparison
equal
deleted
inserted
replaced
219:35be1f8332a9 | 220:8c277a37e2bc |
---|---|
740 def do_shell(self, arg): | 740 def do_shell(self, arg): |
741 'execute a command as if at the OS prompt.' | 741 'execute a command as if at the OS prompt.' |
742 os.system(arg) | 742 os.system(arg) |
743 | 743 |
744 def do_py(self, arg): | 744 def do_py(self, arg): |
745 '''Executes a python command''' | 745 ''' |
746 py <command>: Executes a Python command. | |
747 py: Enters interactive Python mode (end with `\py`). | |
748 ''' | |
746 if arg.strip(): | 749 if arg.strip(): |
747 try: | 750 try: |
748 result = eval(arg, self.pystate) | 751 result = eval(arg, self.pystate) |
749 if result is None: | 752 if result is None: |
750 exec(arg, self.pystate) | 753 exec(arg, self.pystate) |
756 print 'Now accepting python commands; end with `\\py`' | 759 print 'Now accepting python commands; end with `\\py`' |
757 buffer = [self.pseudo_raw_input('>>> ')] | 760 buffer = [self.pseudo_raw_input('>>> ')] |
758 while not buffer[-1].strip().startswith('\\py'): | 761 while not buffer[-1].strip().startswith('\\py'): |
759 try: | 762 try: |
760 buf = '\n'.join(buffer) | 763 buf = '\n'.join(buffer) |
761 result = eval(buf, self.pystate) | 764 try: |
762 if result is None: | 765 result = eval(buf, self.pystate) |
766 print repr(result) | |
767 except SyntaxError: | |
763 exec(buf, self.pystate) | 768 exec(buf, self.pystate) |
764 else: | |
765 print result | |
766 buffer = [self.pseudo_raw_input('>>> ')] | 769 buffer = [self.pseudo_raw_input('>>> ')] |
767 except SyntaxError: | 770 except SyntaxError: |
768 buffer.append(self.pseudo_raw_input('... ')) | 771 buffer.append(self.pseudo_raw_input('... ')) |
769 except Exception, e: | 772 except Exception, e: |
770 print e | 773 print e |