读书人

python札记-包

发布时间: 2012-09-14 11:53:44 作者: rapoo

python笔记---包

包是一种结构化python模块的一种方法。

文件结构如下:

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              ...

?

?

import sound.effects.echo

?这种方式导入后,就要用一下方式使用,很麻烦。

sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)

?

from sound.effects import echo

?这种方式导入一个模块,就要用一下方式使用,还是麻烦。

echo.echofilter(input, output, delay=0.7, atten=4)

?

from sound.effects.echo import echofilter

?这种方式导入,使用就简单些了。

echofilter(input, output, delay=0.7, atten=4)
?

读书人网 >perl python

热点推荐