Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- testtest.py
- testmodulesbase.py
- testmodulesblah.py
- File "modules/blah.py", line 1, in <module>
- from .base import BaseModule
- ImportError: attempted relative import with no known parent package
- #!/usr/bin/env python
- import importlib
- class Test():
- def __init__(self):
- spec = importlib.util.spec_from_file_location("blah", "modules/blah.py")
- mod = importlib.util.module_from_spec(spec)
- spec.loader.exec_module(mod)
- def main():
- t = Test()
- if __name__ == '__main__':
- main()
- class BaseModule():
- modulename = "base"
- def __init__(self,name):
- print("Initializing module %s" % (self.modulename))
- from .base import BaseModule
- class BlahModule(BaseModule):
- modulename = "blah"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement