pass data from optparse to other class instances

Tim Arnold a_jtim at bellsouth.net
Mon Jun 9 17:09:35 EDT 2008


Hi,
I'm writing a command-line interface using optparse. The cli takes
several options with a single action and several parameters to be used
in the resulting worker classes.

I've been passing parameters from optparse to the workers in two ways:
(1) creating a Globals.py module, set parameters once in the cli code
and read it
when needed in the worker class methods. Something like this:
import Globals
class Foo(object):
    def __init__(self):
        if Globals.debug:
            etc
(2) passing a parameter directly to the worker class __init__ method:
class Bar(object):
    def __init__(self, verbose=False):
        etc

Are those methods the best/only ways to pass these parameters around?
What's the smart way to do it?
thanks,
--Tim



More information about the Python-list mailing list