素晴らしいです!

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