# __init__.py # equalizer.py # vocoder.py # karaoke.py # ... # import echo module: import sound.effects.echo # remember sound, effects, echo are all modules, so the function echofilter() # needs to be called as: sound.effects.echo.echofilter() # alternatively, import echo module locally as: from sound.effects import echo # recall this imports module locally, so echofilter() can be called as: echofilter() # alternatively, import echofilter() function locally as: from sound.effects.echo import echofilter() # Importing * from a package # import * imports everything; with packages, should it import all # contents of all submodules too? that could waste time # so programmer should be explicit about which contents to import # this is done in the __init__.py file! # the list __all__ in __init__.py is the list of module to import
fibo = fibo.fib dir() import builtins dir(builtins) # 6.4. Packages import sys sys.path.append('/home/ad.msystechnologies.com/sagar.nikam/Documents/git/learnNPractice/others/language/python/pythonDocsOfficial/6_modules') import sound.effects.echo output=0 sound.effects.echo.echofilter(input, output, delay=0.7, atten=4) from sound.effects import echo output=1 echo.echofilter(input, output, delay=0.7, atten=4) from sound.effects.echo import echofilter echofilter(input, output, delay=0.7, atten=4) # 6.4.1. Importing * From a Package from sound.effects import * import sound.effects.echo import sound.effects.surround from sound.effects import * # 6.4.2. Intra-package References # 6.4.3. Packages in Multiple Directories
def heartbeat(): return echo.echofilter()
# surround.py # reverse.py # ... # filters/ Subpackage for filters # __init__.py # equalizer.py # vocoder.py # karaoke.py # ... import sound.effects.echo # Method 2: Loads the submodule sound.effects.echo. It must be referenced with its full name. sound.effects.echo.echofilter(input, delay = 0.7, atten = 4) # Method 3: An alternative way of importing the submodule from sound.effects import echo # Method 4: Another alternative way of importing the desired function or variable # 1. When using from package import item, the item can be either a submodule (or subpackage) of the package, or some # other name defined in the package, like a function, class or variable. # 2. The import statement first tests whether the item is defined in the package; if not, it assumes it is a module and # attempts to load it. If it fails to find it, an ImportError exception is raised. from sound.effects.echo import echofilter echofilter(input, delay=0.7, atten=4) # Method 5: Importing * From a Package # 1. If a package's __init__.py code defines a list named __all__, it is taken to be the list of module names that # should be imported when from package import * is encountered.
""" 1. from sound.effects import echo 명령어를 통해 echo.py를 호출 합니다. - 이것도 서브 모듈 echo 를 로드하고, 패키지 접두어 없이 사용할 수 있게 합니다. 그래서 이런 식으로 사용할 수 있습니다. 2. echo.py에 존재하는 echofilter()를 호출 합니다. 3. 입력 받는 parameter 값은 4개로 input_value, output_value, delay, atten 입니다. 4. 편의상 숫자로 모두 입력 받겠습니다. 5. 결과는 input_value * delay + output_value * atten 의 계산 결과입니다. """ from sound.effects import echo echo_filter_result = echo.echofilter(5, 4, 3, 2) print(f'echo_filter_result : {echo_filter_result}')
# import sound.effects.echo # print(sound.effects.echo.echofilter()) # from sound.effects import echo # print(echo.echofilter()) # from sound.effects.echo import echofilter # print(echofilter()) # from sound.effects import * from sound.effects import echo print(echo.echofilter()) from sound.filters import vocoder print(vocoder.heartbeat())