dynamic import with heritage
Grégoire Dooms
dooms at info.LESS.ucl.SPAM.ac.be
Fri Jun 11 11:22:30 EDT 2004
marco wrote:
> Grégoire Dooms a écrit :
>
>> 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.
>>
>
> your statement doesn't work
> but it works, if i do :
> -------------------------
> import sys
> sys.path.append("../..")
> from main import bidon
> -------------------------
>
> does it exists a way to do it easier ? (i don't like this technick to
> append a path to sys.path)
>
I wrote
from __main__ import bidon
Not
from main import bidon
__main__ is the namespace of the script you run.
It is always already loaded so you don't need any modification to sys.path.
I would define bidon in base_classes.py, have the script import that
module and have the plugin import __main__ and refer to the bidon it via
from __main__.base_classes import bidon
Otherwise have the script add the directory of base_classes.py to
sys.path and the plugin just
from base_classes import bidon
--
Grégoire Dooms
More information about the Python-list
mailing list