Skip to content
Advertisement

How can I import subpackage?

I have a file structure like this:

JavaScript
JavaScript

Dir2.__init__.py have has the same code, but with .Something2

Something.py has simple add method, Something2.py has simple sub method.

What I need:

JavaScript

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

If I use from .Dir2 import * in Dir1.__init__.py code in test.py 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.

Advertisement

Answer

Probably it is crutch, but I found solve. Now I have this file structure:

JavaScript
JavaScript

And now I can use

JavaScript

And can’t use

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement