Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. testtest.py
  2. testmodulesbase.py
  3. testmodulesblah.py
  4.  
  5. File "modules/blah.py", line 1, in <module>
  6. from .base import BaseModule
  7. ImportError: attempted relative import with no known parent package
  8.  
  9. #!/usr/bin/env python
  10. import importlib
  11. class Test():
  12. def __init__(self):
  13. spec = importlib.util.spec_from_file_location("blah", "modules/blah.py")
  14. mod = importlib.util.module_from_spec(spec)
  15. spec.loader.exec_module(mod)
  16. def main():
  17. t = Test()
  18. if __name__ == '__main__':
  19. main()
  20.  
  21. class BaseModule():
  22. modulename = "base"
  23. def __init__(self,name):
  24. print("Initializing module %s" % (self.modulename))
  25.  
  26. from .base import BaseModule
  27. class BlahModule(BaseModule):
  28. modulename = "blah"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement