Tan Zong Xuan <[email protected]> added the comment:
I am also trying to use argparse interactively, but in this case by combining
it with the cmd module. So I'm doing something like below:
class MyCmd(cmd.Cmd):
parser = argparse.ArgumentParser(prog='addobject')
parser.add_argument('attribute1')
parser.add_argument('attribute2')
parser.add_argument('attribute3')
def do_addobject(self, line):
args = MyCmd.parser.parse_args(line.split())
newobject = object(args.attribute1, args.attribute2, args.attribute3)
myobjects.append(newobject)
I'm faced with the same problem that when given invalid input, parse_args exits
the program completely, instead of exiting just to the Cmd shell.
I have the feeling that this use case is sufficiently common such that it would
be good if people did not have to override the exit method themselves, and
instead an alternative to parse_args was provided that only raises exceptions
for the surrounding code to handle rather than exiting the program entirely.
----------
nosy: +ZOMGxuan
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue9938>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com