BonelessCurv
BonelessCurv

Reputation: 29

Import modules inside of an __init__ file

I'm trying to create a module with several folders inside of it, each with their own __init__.py file. My file structure looks like this:

| module
| __init__.py
| module1
|| __init__.py
|| a.py
| module2
|| __init__.py
|| b.py

I'm trying to make it so when I reference the original module, I can do something like this:

module.module1.a()

But when I try to import the modules within the top level __init__.py, it says that the modules aren't found. What can I do to fix this?

Upvotes: 0

Views: 47

Answers (1)

BonelessCurv
BonelessCurv

Reputation: 29

I found that you have to use the top module name, as in import module.module1 in the top level __init__.py.

Upvotes: 1

Related Questions