A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2009-October/092423.html below:

[Python-Dev] PEP 389: argparse - new command line parsing module

[Python-Dev] PEP 389: argparse - new command line parsing moduleAndrew McNabb amcnabb at mcnabbs.org
Thu Oct 1 00:58:00 CEST 2009
On Wed, Sep 30, 2009 at 02:40:20PM -0700, Steven Bethard wrote:
> 
> > 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

This looks much easier than what I was able to do in optparse.  Cool.

-- 
Andrew McNabb
http://www.mcnabbs.org/andrew/
PGP Fingerprint: 8A17 B57C 6879 1863 DE55  8012 AB4D 6098 8826 6868
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4