dynamic import
Karl Scalet
news at yebu.de
Mon May 26 07:48:51 EDT 2003
Richard Mertens schrieb:
> i have a python file which i use as library
>
> verb_1.py
>
>
>
> host="test"
> test1="asdf"
> class cConfig:
> def __init__(self):
> self.x="test"
>
>
>
> In my main python file i want to import this file (and his variables)
> dynamic
>
> nr="1"
> __import__("verb_"+nr)
>
> print host
__import__ is a builtin function that returns the module,
nr='1'
verb_x = __import__('verb_'+nr)
print verb_x.host
works for me.
>
> but i get the following error message
> ...
>
Karl
More information about the Python-list
mailing list