1

I am trying to import python files programmatically using importlib.

For instance, given a file "a/b/some_file.py", and given also there are no __init__.py files in any of those directories (nor can I add them), what is the best way to import it?

What I tried doesn't seem like it's correct: (After lunching the prompt from "a"'a parent directory and adding it to the path)

 >>> importlib.import_module('a.b.some_file')
ImportError: No module named a.b.some_file

I also tried a relative import but the result is the same.

Jir
  • 2,985
  • 8
  • 44
  • 66

0 Answers0