[FRPythoneers] dispatching from a script

Casey Duncan casey at pandora.com
Fri Apr 15 11:35:45 MDT 2011


You could perhaps define each action as a function or class, and put it into a dictionary keyed by __name__ to dispatch from. Then put the help text in the docstring of the action, and extract it when --help is invoked via the action's __doc__ attribute.

-Casey

On Apr 15, 2011, at 10:29 AM, Brent Pedersen wrote:

> hi, not sure if this list is the appropriate venue, but i'll ask anyway.
> so i have a python library and i want to have several scripts but keep
> them in the same name space.
> so i'll have "mymodule" that's importable from python and then i want
> to be able to have console scripts
> like:
> 
> $ mymodule action_a --args files
> $ mymodule actoin_b --other_args other_files
> etc.
> 
> i can do this manually with something like:
> 
> 
> entry_points={
>      'console_scripts': ['mymodule = mymodule:main']
>      },
> 
> in my setup.py, and dispatching from main() based on sys.argv[2], but then
> after implementing stuff like having
> 
> $ mymodule
> 
> give a list of available actions, it can get pretty tedious.
> are there idioms or modules in python that make this easier?
> i admit i haven't looked around too much.
> 
> thanks for any pointers,
> -brent
> _______________________________________________
> This message sent by the FRPythoneers mailing list.
> Unsubscribe: echo unsubscribe | FRPythoneers-request at lists.community.tummy.com
> URL: http://lists.community.tummy.com/mailman/listinfo/frpythoneers




More information about the FRPythoneers mailing list