정상적인 제어
import math
math.floor(2.5) # 모듈 내부의 기능을 개발자가 호출
제어 역전
from flask import Flask
app = Flask(__name__) # Flask가 서버를 실행한 뒤
@app.route("/")
def hello(): # 개발자의 코드 실행
return "Hello World!"
함수의 앞뒤에 꾸밀 부가적인, 반복할 내용을 정의
def test(function):
def wrapper():
print("시작")
function()
print("끝")
return wrapper
@test
def hello():
print("hello")
hello()
실행결과: 시작
hello
끝
functools 모듈 사용 가능
폴더 내부에 하나 이상의 모듈
패키지에서 가장 먼저 실행
패키지 내부의 모듈들을 한꺼번에 가져오고 싶을 때 사용
# from test_package import * 할 때 가져올 모듈 설정
__all__ = ["module_a", "module_b"]