[Python-ideas] Command line options

Tal Einat taleinat at gmail.com
Wed Apr 18 22:09:40 CEST 2007


On 4/18/07, Thomas Heller <theller at ctypes.org> wrote:
>
> Sometimes I think it would be great if it were possible to have standard
> Python command line options that would allow
>
> - initialize and configure the logging module
> - specify requirements for pkg_resources (for eggs installed with
> --multi-version
>
> All this would avoid having to change logging options or requirements in
> the
> script, or having to implement a command line parser for this stuff in
> every script.
> The idea is to call python in this way:
>
>   python --require foo==dev --logging level=DEBUG myscript.py
>
>
>
> I have not been able to implement something like this in sitecustomize.py,
> because this module is executed when sys.argv is not yet available.
>
> Another possible way to implement this would probably be to set
> environment vars
> and parse those in sitecustomize.py, you would have to call
>
>   env option1=foo option2=bar python script.py
>
> then; unfortuately windows does not have an 'env' utility.
>
> Does this sound like a useful idea?
>
> Thomas


-1 on this. IMHO these options are too specific to be part of Python's
standard command line options. And using environment variables as a
workaround... would cause all sorts of problems, like the one you mentioned.

If these are options you often use for different Python scripts, you could
create a generic Python script runner which would parse these options,
initialize whatever is required (logging, packages, etc.) and finally
execfile the given Python script. For example:

script_runner.py --require foo==dev --logging level=DEBUG myscript.py

- Tal
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20070418/f1804844/attachment.html>


More information about the Python-ideas mailing list