[Python-Dev] PEP 389: argparse - new command line parsing module (original) (raw)
Steven Bethard steven.bethard at gmail.com
Wed Sep 30 23:40:20 CEST 2009
- Previous message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Next message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Sep 30, 2009 at 1:17 PM, Andrew McNabb <amcnabb at mcnabbs.org> wrote:
>From my cursory reading of the documentation, it looks like argparse can only add subparsers for subcommands. Is there any way to add subparsers based on options instead (as iptables does)?
Currently this is not supported, but it would be a nice feature.
Also, is it possible to add these subparsers dynamically? For example, you would want to be able to load a module immediately after parsing the name instead of having to keep a predetermined list of all module names. I'm pretty sure that bzr dynamically loads modules this way. Can argparse help with this?
You can probably already do this. I'm not 100% sure what you want to do, but it's certainly possible to define an argparse.Action that loads a module when it's invoked. It might look something like::
class MyAction(argparse.Action):
def __call__(self, parser, namespace, value, option_string=None):
mod = __import__(value) # or whatever
Steve
Where did you get that preposterous hypothesis? Did Steve tell you that? --- The Hiphopopotamus
- Previous message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Next message: [Python-Dev] PEP 389: argparse - new command line parsing module
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]