0

so I have a module/directory called A and it has init.py file and in it, it has another module/directory called B which have its init.py and a file called function.py which has a function called dummy()

here is the structure of directories

A
|-- __init__.py
|
|-- B
    |
    |-- __init__.py
    |-- function.py

so what I want is to be on the same directory that contains directory A and do that

from A import *
dummy()

what I have done is do that in B/init.py

from dummy import *

and that in A/init.py

import B

and I can do that

from A.B import *

I want to write A instead of A.B

Omar Khalid
  • 324
  • 1
  • 3
  • 15

1 Answers1

1

I changed your import code a bit and it seems to work now like you wanted. So in the B directory's init.py it has:

# __init__.py in B
from .function import *

In the A directory's init.py:

# __init__.py in A
from .B import *

Now, when I run Python shell in the directory that contains A and and use from A import *, it calls dummy() with no problem.

However, there are discussions on using wildcard imports in Python. Check this post for example: Should wildcard import be avoided?

Floydovich
  • 106
  • 2
  • 4