changeset 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
files cmd2.py
diffstat 1 files changed, 8 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Wed Mar 18 15:32:08 2009 -0400
+++ b/cmd2.py	Wed Mar 18 18:27:29 2009 -0400
@@ -742,7 +742,10 @@
         os.system(arg)
         
     def do_py(self, arg):  
-        '''Executes a python command'''
+        '''
+        py <command>: Executes a Python command.
+        py: Enters interactive Python mode (end with `\py`).
+        '''
         if arg.strip():
             try:
                 result = eval(arg, self.pystate)
@@ -758,11 +761,11 @@
             while not buffer[-1].strip().startswith('\\py'):
                 try:
                     buf = '\n'.join(buffer)
-                    result = eval(buf, self.pystate)
-                    if result is None:
+                    try:
+                        result = eval(buf, self.pystate)
+                        print repr(result)
+                    except SyntaxError:
                         exec(buf, self.pystate)
-                    else:
-                        print result
                     buffer = [self.pseudo_raw_input('>>> ')]
                 except SyntaxError:
                     buffer.append(self.pseudo_raw_input('... '))