summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcmd2.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/cmd2.py b/cmd2.py
index 618ccf4..5b0e7fd 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -744,21 +744,23 @@ class Cmd(cmd.Cmd):
def do_py(self, arg):
'''
py <command>: Executes a Python command.
- py: Enters interactive Python mode (end with `\py`).
+ py: Enters interactive Python mode (end with `end py`).
'''
if arg.strip():
try:
result = eval(arg, self.pystate)
- if result is None:
+ print repr(result)
+ except SyntaxError:
+ try:
exec(arg, self.pystate)
- else:
- print result
+ except Exception:
+ raise
except Exception, e:
print e
else:
- print 'Now accepting python commands; end with `\\py`'
+ print 'Now accepting python commands; end with `end py`'
buffer = [self.pseudo_raw_input('>>> ')]
- while not buffer[-1].strip().startswith('\\py'):
+ while buffer[-1].lower().split()[:2] != ['end','py']:
try:
buf = '\n'.join(buffer)
try: