Python: Is it meaningful to import sub-package?

Viewed 576

This statement is from Python 3 Doc:

Note that when using from package import item, the item can be either a submodule (or subpackage) of the package ...

It says we can from package import subpackage.

Here I create a package audio, and two subpackage format and sound.

enter image description here

Then I import its subpackage :

from audio import sound

print(type(sound))

The output is

class 'module'

It shows that for from package import subpackage, Python intepreter always takes the item as module, not subpackage.

from audio import sound

print(type(sound.echo))

Moreover, since sound is taken as module, how to access its echo module?

it will raise

AttributeError: module 'audio.sound' has no attribute 'echo'

Hence, I wonder whether it is meaningful to import sub-package, or is it possible to import subpackage?

1 Answers
Related