Reputation: 401
I made a project that is a collection of code and seperated them to make it easy to publish to PyPi. I have this directory here:
foo
| __init__.py
|
\---coordinates
| __init__.py
|
\---coordinates
coordinates.py
__init__.py
However, when i import foo, it does not recognise the coordinates submodule.
>>>import foo
>>>dir(foo)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
>>>foo.coordinates
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'foo' has no attribute 'coordinates'
What am I doing wrong?
Upvotes: 0
Views: 63
Reputation: 171
There isn't any point in doing what you are doing.
Try doing from foo.coordinates.coordinates import coordinates
.
If you still want to do foo.coordinates
you must add import [submodule_name]
like import coordinates
in your __init__.py
.
Upvotes: 1