I have a script in python that can be invoked from the command-line and uses
optparse.script -i arg1 -j arg2In this case I use
(options, args) = parser.parse_args()to createoptionsthen useoptions.arg1to get arguments.But I also want it to be importable as a module.
from script import * function(arg1=arg1, arg2=arg2)I've managed to do this using a really lame solution: by providing a dummy object.
def main(): class Options: ''' dummy object ''' def __init__(self): pass options = Options for k in kwargs: setattr(options, k, kwargs[k])
The rest of the script doesn't know the difference but I think this solution is fugly.
Is there a better solution to this?
for k in **kwargs:? can you paste the actual code you are using?object().