Loading a module by expanding a string variable?
Joakim Hove
hove at phys.ntnu.no
Thu Oct 26 17:07:24 EDT 2000
Hello,
I have written two modules Mod1 and Mod2, and then I want load either
Mod1 or Mod2 - depending on the value of a string variable.
Example script:
#!/usr/local/bin/python
module = "Mod1"
from module import *
What I wanted here was the module Mod1 to be loaded, as this is the
current value of the module variable. But this obviously fails, as the
interpreter tries to load a module literally named "module" - which
does not exist.
Is there any way I can achieve the effect I want?
Regards - Joakim Hove
--
=== Joakim Hove www.phys.ntnu.no/~hove/ ======================
# Institutt for fysikk (735) 93637 / E3-166 | Skøyensgate 10D #
# N - 7491 Trondheim hove at phys.ntnu.no | N - 7030 Trondheim #
================================================ 73 93 31 68 ========
More information about the Python-list
mailing list