I hava a package a and the tree is:
a/
/__init__.py
/b.py
And how can I import a.b as a_.b ?
You'll have to do it in two lines:
import a as a_
from a import b
print(a_.b)
# <module 'a.b' from '.\\a\\b.py'>
Or:
import a as a_
import a.b
print(a_.b)
# <module 'a.b' from '.\\a\\b.py'>
The first has the disadvantage that it puts b into your namespace and the second has the disadvantage that it puts a into your namespace. If you want to, you can fix that by using del b and del a, respectively.
Alternatively, you can also write the second line as from a import b as _ or import a.b as _, respectively, which will prevent b and a from appearing in your namespace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With