0

In the below code how are we able to call

packA.a1.a1_func()
in
start.py
? From my understanding, to be able to do this, we would need to have the statement
from packA import a1
in
test/packA/__init__.py
. In the current setting, I believe only
packA.packA_func()
and
packA.a1_func()
would be valid statements in
start.py
. Thank you!

test/packA/a1.py

def a1_func():
    print("running a1_func()")

test/packA/init.py

## this import makes a1_func directly accessible from packA.a1_func
from packA.a1 import a1_func

def packA_func():
    print("running packA_func

test/start.py

import packA  # "import packA.a1" will work just the same

packA.packA_func()
packA.a1_func()
packA.a1.a1_func()

output of running python start.py:

running packA_func()
running a1_func()
running a1_func

Source : https://chrisyeh96.github.io/2017/08/08/definitive-guide-python-imports.html

Anonymous Asked question May 14, 2021