20230116_Writing_Function_in_Python

eenimeeniminim0·2023년 1월 16일
0

Datacamp

목록 보기
6/16

Lesson Learned

Chapter 1 - Best Practices

  • Docstrings
  • DRY and Do One Thing
  • Pass by assignment(mutable vs immutable)

Chapter 2 - Context Managers

with my_context_manager() as value:
# do something
@contextlib.contextmanager
def my_function():
# this function can be used in a “with” statement now 

Chapter 3 - Decorators

@my_decorator
def my_decorated_function():
# do something
def my_decorator(func):
   def wrapper(*args, **kwargs):
      return func(*args, **kwargs)
   return wrapper

Chapter 4 - More on Decorators

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
  • decorator 추가 공부 필요
profile
데이터와 사회과학 사이를 여행하는 히치하이커를 위한 안내서

0개의 댓글