1. 程式人生 > >python - from … import …

python - from … import …

ever round bpa ini ports mat leading imp involved

from . import XXX 默認的就是在當前程序所在文件夾裏__init__.py程序中導入XXX from .A import XXX 如果當前程序所在文件夾裏沒有__init__.py文件,導入A.py文件,A是指當前文件夾下你想導入的函數(或者其他的)的python程序名 如果你想導入的函數不在當前文件夾,那麽就有可能用到 from .. import XXX(即上一個文件夾中的__init__.py),或者from .. A import XXX(即上一個文件夾中的文件A)
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
  You can also write relative imports, with the from module import name form of import statement. These imports use leading dots to indicate the current and parent packages involved in the relative import. From the surround module for example, you might use:
from
. import echo from .. import formats from ..filters import equalizer

python - from … import …