Initializing a python module with parameters
Erik Max Francis
max at alcyone.com
Wed Dec 4 18:21:06 EST 2002
Iggeres Bet wrote:
> The perfect solution would be a:
>
> # Calling a module constructor
> import mymodule(<parameters>)
>
> I can write:
> import mymodule
> mymodule.init(<parameters>)
>
> But I don't see this code explicit and elegant. What is the best way
> to pass initialization parameters to a Python module?
Since there is no way to do what you want natively in Python (there's no
concept of parameters that you can pass to a module on importing),
elegance isn't really an option :-). The latter approach is probably a
customary way, though depending on the options involved, they might make
sense as parameters to the constructor of a _class_ in the module, or
something similar. Without details about exactly what those parameters
are for, it's hard to say if this would make more sense.
--
Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/ \ The little I know, I owe to my ignorance.
\__/ Sacha Guitry
Polly Wanna Cracka? / http://www.pollywannacracka.com/
The Internet resource for interracial relationships.
More information about the Python-list
mailing list