Skip to content
Advertisement

How to import dynamic module within a sub directory

I am dynamically importing files/modules using import_module. When I had the files in the same directory this worked:

JavaScript

However, when I reorganized my folder structure to look this:

JavaScript

I assumed that I could do this:

JavaScript

But it gives me the error

ModuleNotFoundError: No module named ‘child’

I tried the following paths as well:

  • /sub/child
  • ./sub/child

Advertisement

Answer

import_module() takes a module name, not a file path, as an argument. This means you must use . not /:

JavaScript
Advertisement