dynamic import with heritage

Grégoire Dooms dooms at info.ucl.ac.be
Fri Jun 11 03:57:00 EDT 2004


In your dhuile package, you need bidon in your namespace.
This can be done by importing the module containing bidon's definition.
According to what you say ("here my main"), this module is __main__ .

So a simple
from __main__ import bidon
class vidange(bidon):
    pass
should do the job.

If you want your dhuile package to be more portable, it would be better 
to define bidon in a separate module (e.g. a "contenants.py" module ) 
and get both your main and dhuile import it.

Hope it helps.
--
Grégoire Dooms

marco wrote:

> i try to make a dynamic import of a plugin which herits from another 
> class
>
> here my main:
> -------------------------------------------------------------------
> class bidon:
>     pass
>
> plugin = __import__( "plugins.dhuile" , globals(), locals())
> -------------------------------------------------------------------
>
> And in the file /plugins/dhuile/__init__.py, i've got :
> -------------------------------------------------------------------
> class vidange(bidon):
>     def test():
>         return "ok"
> -------------------------------------------------------------------
>
> python2.3 gives me :
> "__init__.py : NameError: name 'bidon' is not defined"
>
> i don't understand where is the mistake ?!
> (class "bidon" is in passed by the globals() ... but it seems 
> __init__.py doesn't understand)
>
> anybody have got an idea ?
> thanx






More information about the Python-list mailing list