diff options
author | Diego Roversi <diegor@tiscali.it> | 2019-09-20 11:26:13 +0200 |
---|---|---|
committer | Diego Roversi <diegor@tiscali.it> | 2019-09-20 11:26:13 +0200 |
commit | 292c8b2b06c71ef4f08b3b99a3545365261ef2d2 (patch) | |
tree | 02ea4729a871dc996d0867b9fb22938d78eddf38 /display | |
parent | 4f178917c2a1bf78a612454fd830b87d78dd1772 (diff) |
fix dynamic import
Diffstat (limited to 'display')
-rw-r--r-- | display/modes.py | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/display/modes.py b/display/modes.py index 0ac680e..c43638d 100644 --- a/display/modes.py +++ b/display/modes.py @@ -1,4 +1,7 @@ import sys +import importlib +import traceback +# import display.dpy_pygame KeyPressed = 2 KeyReleased = 3 @@ -32,20 +35,27 @@ class Mode: self.url = url def getmodule(self): - return __import__(self.prefix + self.name.lower(), globals(), - locals(), ['available']) +# import dpy_pygame + print( f"getmodule __import__ {self.prefix}{self.name.lower()}", file=sys.stderr ) + return importlib.import_module( "display." + self.prefix + self.name.lower() ) + #__import__(self.prefix + self.name.lower(), globals(), + # locals(), ['available']) def imperror(self): try: return self.__imperror except AttributeError: try: + print( f"getmodule = {self}" ) module = self.getmodule() - except ImportError: + except ImportError as e: result = 'not installed' + print("== ImportError traceback:", file=sys.stderr ) + traceback.print_exc(file=sys.stderr) else: result = hasattr(module, 'imperror') and module.imperror() self.__imperror = result + print( f"imperror result={result}" ) return result def unique_id(self): |