使用程序包布局here:
sound/ Top-level package
__init__.py Initialize the sound package
formats/ Subpackage for file format conversions
__init__.py
wavread.py
wavwrite.py
aiffread.py
aiffwrite.py
auread.py
auwrite.py
...
effects/ Subpackage for sound effects
__init__.py
echo.py
surround.py
reverse.py
...
filters/ Subpackage for filters
__init__.py
equalizer.py
vocoder.py
karaoke.py
...
似乎我可以同时做:
from sound.effects import echo
和
import sound.effects.echo as echo
这两种语法有什么区别?
编辑。我发现的区别是:
import sound.effects
del sound.effects
from sound.effects import echo # ok
from sound.effects import echo as echo # ok
import sound.effects.echo # ok
import sound.effects.echo as echo # fail
这已在python 3.6上进行了测试;在python 3.7上一切正常;