-
19. 01. 2010, 14:25 #1
Python Module dynamisch neuladen
Ich programmiere zur Zeit an einem kleinen Python Projekt, das ein Hauptmodul hat, welches gestartet wird. Dieses wiederum importiert dynamisch vorher registrierte Events aus anderen Modulen:
Es ist sichergestellt, dass die importierten Module nur jeweils ihre Events beinhalten und keine weiteren globalen Variables, so dass hoffentlich keine Namenskonflikte auftreten sollten. (Falls jemand eine Idee hat, wie ich das schöner implementieren kann, ich bin dafür offen.)PHP-Code:for plugin in PLUGINS:
exec(b"from " + plugin + b" import *")
Jetzt will ich ein Event namens "!reload" registrieren mit dem ich dann einzelne Module neuladen kann, weil ich darin was verändert habe, ohne das ganze Skript jedoch neustarten zu müssen.
Jetzt mein Problem, ich habe einfach das obige Statement für das entsprechende Modul erneut ausgeführt, jedoch scheint das nichts zu bringen, sprich es werden immer noch die alten Funktionen aufgerufen?
Laut den docs sollte das IMHO gehen:
Ich benutze Python 3.1If a module imports objects from another module using from ... import ..., calling reload() for the other module does not redefine the objects imported from it — one way around this is to re-execute the from statement, another is to use import and qualified names (module.*name*) instead.
greets
-
20. 01. 2010, 02:43 #2
Re: Python Module dynamisch neuladen
http://lucumr.pocoo.org/2006/7/30/setuptools-pluginsFalls jemand eine Idee hat, wie ich das schöner implementieren kann, ich bin dafür offen.
http://aroberge.blogspot.com/2008/12...ols-based.html
http://base-art.net/Articles/64/
-
20. 01. 2010, 18:15 #3
Re: Python Module dynamisch neuladen
Sieht ein wenig aus wie Overkill.
Kann man da Plugins zur Laufzeit auch erneut laden?
-
21. 01. 2010, 16:32 #4Mitglied
- Registriert seit
- Jun 2003
- Beiträge
- 209
Re: Python Module dynamisch neuladen
Für das dynamische Importieren von Modulen kann __import__ verwendet werden. Das Neuladen von Modulen, sollte mit imp.reload möglich sein.
-
21. 01. 2010, 18:31 #5
Re: Python Module dynamisch neuladen
imp.reload funktioniert in meinem Fall nicht, siehe:
und das import Statement funktioniert glaube ich nicht mit absoluten Filenamen.If a module imports objects from another module using from ... import ..., calling reload() for the other module does not redefine the objects imported from it — one way around this is to re-execute the from statement, another is to use import and qualified names (module.*name*) instead.
-


Zitieren

mehr lesen...







FoWL: Unterstützungserklärung für...
Heute, 12:14 in gulli:news