Passing options around your program

alisonken1 alisonken1 at gmail.com
Sun May 7 23:03:45 CEST 2006


Leo Breebaart wrote:
> I have another question where I am not so much looking for a
> solution but rather hoping to get some feedback on *which*
> solutions people here consider good Pythonic ways to approach a
> issue.
>
> The situation is this: I am writing fairly large console scripts
> in Python. They have quite a few command-line options, which lead
> to configuration variables that are needed all over the program
> (e.g. the "--verbose" option alone is used by just about every
> function and method).

<SNIP>

One question I have is about the "--verbose" option.

If you're doing something that is equivalent to logging to <file |
console>, rather than continuing to pass the '--verbose' flag around,
why not just use the built-in logging facility to manage the extra
output?

By having the different modules call logging( <level>, "<message">)
throughout your programs, you only need to set the initial level from
where you're checking options (whether from command line or
configuration file) rather than having to pass the '--verbose' option
around.




More information about the Python-list mailing list