Skip to content

How can I import subpackage?

I have a file structure like this:
from .Something import * have has the same code, but with .Something2 has simple add method, has simple sub method.

What I need:
import Dir1
print(Dir1.Dir2.sub(10, 14))

But I get an error AttributeError: module 'Dir1' has no attribute 'Dir2'.

If I use from .Dir2 import * in code in works, but also works print(Dir1.sub(10, 14)), what I don’t want. I tryed many variants, but they brought me to error or Dir1.sub working.

This can probably be found on the Internet, but my knowledge of English is suffering and I may miss the answer. Of course I’ve already tried searching for it on the Internet.

I will be very grateful for your answer.


Probably it is crutch, but I found solve. Now I have this file structure:
import Dir1 as Add
from .Dir1 import Dir2 as Sub

And now I can use
import Dir1
print(Dir1.Sub.sub(10, 7))

And can’t use
import Dir1
print(Dir1.sub(10, 7))