Yet another python imports question.
I have a directory structure
thing
|- __init__.py
|- run.py
|- mod
|- __init__.py
|- what
|- __init__.py
|- yo.py
The contents of yo.py
are
class Yo:
def __init__(self):
print("initialized What")
And the contents of my run.py
are
from mod.what import yo
y = yo.Yo
print(y)
y()
Everything works great.
<class 'mod.what.yo.Yo'>
initialized What
But I need to import like this:
from mod import what
y = what.yo.Yo
print(y)
y()
and then I get
Traceback (most recent call last):
File "/Users/pavelkomarov/Desktop/thing/run.py", line 4, in <module>
y = what.yo.Yo
AttributeError: module 'mod.what' has no attribute 'yo'
Why? I've got __init__.py
s out the wazoo. Shouldn't python be able to find the class? This structure is important to me because I have a lot of classes below a certain module and need to be able to access them all, preferably without having to do more granular imports of each one, which takes a ton of code.