This is a demo package to show the implementation details of python import system. Collect the above py files into a folder app
.
The folder orginization is
root
├── ext.py
│
├── app
│ ├── __init__.py
│ ├── a.py
│ ├── b.py
│ ├── ...
Outside the app folder, run python3 -m app.c
.
The stdout is shown below.
------------
you are now entering __main__
c module is now as __main__
in c, import a
------------
you are now entering app.a
before create class A
end create class A
before create obja
initialization of obja
end create obja
end of app.a
------------
in c, import b
------------
you are now entering app.b
in b, import a
initialize list b as [1]
assign attr b to obja
create function modif_list
create function modif_list2
create function pre_defined
begin change the listb
import c in function modify_list2 within b
------------
you are now entering app.c
c module is now as app.c
in c, import a
in c, import b
init tuplec as (2,)
in c, obja.b: 2
in c, listb: [1]
end of app.c
------------
end change the listb
end of app.b
------------
init tuplec as (2,)
in c, obja.b: 2
in c, listb: 2
end of __main__
------------
You can also try python3 -m app.e
or python3 ext.py
, the stdout for the latter is
entering app.e
entering app.f
finish import e in f
finish register of fun f1
finish register of fun f2
finish import f in e
finish register of fun e1
finish register of fun e2
finish import e from ext
finish import f from ext
call e2 in ext
e2
f1
call f2 in ext
f2
e1