수고하셨습니다!

Python으로 함수 작성하기

Shayne Miel

Software Architect @ Duo Security

1장 - 모범 사례

  • 독스트링
  • DRY 원칙과 단일 책임
  • 할당에 의한 전달 (가변 vs 불변)
Python으로 함수 작성하기

2장 - 컨텍스트 관리자

with my_context_manager() as value:
  # do something
@contextlib.contextmanager
def my_function():
  # this function can be used in a "with" statement now
Python으로 함수 작성하기

3장 - 데코레이터

@my_decorator
def my_decorated_function():
  # do something
def my_decorator(func):
  def wrapper(*args, **kwargs):
    return func(*args, **kwargs)
  return wrapper
Python으로 함수 작성하기

4장 - 데코레이터 심화

def my_decorator(func):
  @functools.wraps(func)
  def wrapper(*args, **kwargs):
    return func(*args, **kwargs)
  return wrapper
Python으로 함수 작성하기

4장 - 데코레이터 심화

def decorator_that_takes_args(a, b, c):
  def decorator(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
      return func(*args, **kwargs)
    return wrapper
  return decorator
Python으로 함수 작성하기

감사합니다!

Python으로 함수 작성하기

Preparing Video For Download...