Excellent travail !

Écrire des fonctions en Python

Shayne Miel

Software Architect @ Duo Security

Chapitre 1 - Bonnes pratiques

  • Docstrings
  • DRY et « Do One Thing »
  • Passage par affectation (mutable vs immutable)
Écrire des fonctions en Python

Chapitre 2 - Gestionnaires de contexte

with my_context_manager() as value:
  # do something
@contextlib.contextmanager
def my_function():
  # this function can be used in a "with" statement now
Écrire des fonctions en Python

Chapitre 3 - Décorateurs

@my_decorator
def my_decorated_function():
  # do something
def my_decorator(func):
  def wrapper(*args, **kwargs):
    return func(*args, **kwargs)
  return wrapper
Écrire des fonctions en Python

Chapitre 4 - Aller plus loin avec les décorateurs

def my_decorator(func):
  @functools.wraps(func)
  def wrapper(*args, **kwargs):
    return func(*args, **kwargs)
  return wrapper
Écrire des fonctions en Python

Chapitre 4 - Aller plus loin avec les décorateurs

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
Écrire des fonctions en Python

Merci !

Écrire des fonctions en Python

Preparing Video For Download...