summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcatherine <catherine@Elli.myhome.westell.com>2009-03-18 18:27:29 -0400
committercatherine <catherine@Elli.myhome.westell.com>2009-03-18 18:27:29 -0400
commit43824eb0e7be9561802717a7c08f3e0653fa7836 (patch)
tree457ad4084437f1eef00d42d6316c2103fd38043b
parentfed688afdd4e50f9d09d3a9d1b98b2d674804231 (diff)
downloadcmd2-hg-43824eb0e7be9561802717a7c08f3e0653fa7836.tar.gz
yay py works fully
-rwxr-xr-xcmd2.py13
1 files changed, 8 insertions, 5 deletions
diff --git a/cmd2.py b/cmd2.py
index 37719ff..618ccf4 100755
--- a/cmd2.py
+++ b/cmd2.py
@@ -742,7 +742,10 @@ class Cmd(cmd.Cmd):
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 @@ class Cmd(cmd.Cmd):
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('... '))