[Python-de] Dynamisch Module Nachladen wenn die Namen erst zur Laufzeit bekannt sind?
Andrew Smart
subscriptions at smart-knowhow.de
Do Nov 15 22:57:50 CET 2007
> -----Ursprüngliche Nachricht-----
> Von: python-de-bounces at python.net
> [mailto:python-de-bounces at python.net] Im Auftrag von Hartmut Goebel
> Gesendet: Donnerstag, 15. November 2007 21:37
> An: Die Deutsche Python Mailingliste
> Betreff: Re: [Python-de] Dynamisch Module Nachladen wenn die
> Namen erst zur Laufzeit bekannt sind?
>
> Andrew Smart schrieb:
>
> > Dafür bietet sich __import__ an. Bei quellenlosen Plugins
> Müsste man
> > mal probieren statt .py .pyc zu laden. Hab ich aber noch nicht
> > ausprobiert.
>
> Der Import ist doch nicht das Problem. Das Problem ist vorher
> festzustellen, welche Module/Packages es gibt.
Da hast Du auch wieder recht. Was ich meinte war: __import__ ist besser
geeignet für Packages als load_module.
Zitat Hilfe von "find_module":
This function does not handle hierarchical module names (names containing
dots). In order to find P.M, that is, submodule M of package P, use
find_module() and load_module() to find and load package P, and then use
find_module() with the path argument set to P.__path__. When P itself has a
dotted name, apply this recipe recursively.
Klingt umständlich. Also __import__.
Packages identifizieren: Alternativ entweder nach __init__.py suchen (weil
das dann ein Package andeutet), oder find_module verwenden (s.o.) und dann
per __import__ versuchen zu laden.
Wie auch immer... gehen tuts :-)
Viele Grüße,
Andrew
Mehr Informationen über die Mailingliste python-de