Inspect's getmembers - ich dreh noch durch
Verfasst: Montag 23. Januar 2017, 21:40
Hallo liebes Forum!
Ich sitze gerade vor folgendem Problem (gekürzte Variante):
Hatte jemand von euch schon einmal das Problem? Woran kann das liegen? Ich sitze jetzt schon ein Weilchen davor
und seh' vll. den Wald vor lauter Bäumen nicht... bin um jede Hilfe dankbar!
Ich sitze gerade vor folgendem Problem (gekürzte Variante):
Code: Alles auswählen
from inspect import getmembers, isfunction
import imp
class ScriptLoader():
def __init__(self):
## code
def load_scripts(self,path): # path is path to some .py-module
module = imp.load_source('scripts.name', path)
return getmembers(module,isfunction)
class Loader1():
def __init__(self):
self.sl = ScriptLoader()
## more code
def loadme(self,path):
print self.sl.load_scripts(path)
class Loader2():
def __init__(self):
self.sl = ScriptLoader()
## even more code
def loadit(self,path):
print self.sl.load_scripts(path)
if __name__ == '__main__':
l1 = Loader1()
l2 = Loader2()
l1.loadme(path_1) # ---> correct output, functions of module on path_1
l2.loadit(path_2) # ---> correct output, functions of module on path_2
l1.loadme(path_1) # ---> WRONG, functions of module on path_2
und seh' vll. den Wald vor lauter Bäumen nicht... bin um jede Hilfe dankbar!