diff options
author | catherine <catherine@Elli.myhome.westell.com> | 2009-03-18 18:27:29 -0400 |
---|---|---|
committer | catherine <catherine@Elli.myhome.westell.com> | 2009-03-18 18:27:29 -0400 |
commit | 43824eb0e7be9561802717a7c08f3e0653fa7836 (patch) | |
tree | 457ad4084437f1eef00d42d6316c2103fd38043b | |
parent | fed688afdd4e50f9d09d3a9d1b98b2d674804231 (diff) | |
download | cmd2-hg-43824eb0e7be9561802717a7c08f3e0653fa7836.tar.gz |
yay py works fully
-rwxr-xr-x | cmd2.py | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -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('... '))
|