This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author tanqazx
Recipients bethard, docs@python, eric.araujo, jayt, tanqazx
Date 2010-12-16.09:04:50
SpamBayes Score 8.5466034e-08
Marked as misclassified No
Message-id <1292490291.69.0.256290903882.issue9938@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2010-12-16 09:04:51tanqazxsetrecipients: + tanqazx, bethard, eric.araujo, docs@python, jayt
2010-12-16 09:04:51tanqazxsetmessageid: <1292490291.69.0.256290903882.issue9938@psf.upfronthosting.co.za>
2010-12-16 09:04:50tanqazxlinkissue9938 messages
2010-12-16 09:04:50tanqazxcreate