Loading a module by expanding a string variable?
Joakim Hove
hove at phys.ntnu.no
Thu Oct 26 17:51:23 EDT 2000
"Fredrik Lundh" <effbot at telia.com> writes:
> if you trust whoever sets the module variable, and don't mind
> compiling code on the fly, you can also use exec:
>
> exec "from %s import *" % module
This did the trick - thanks a lot.
> (if you don't trust the source, consider what happens if module is
> set to e.g "os import *; system('rm -rf $HOME') #")
I write the modules myself - so I guess I have to trust the source -
but thanks for the warning anyway.
Joakim
--
=== 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