일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
- shiba
- DWG
- 715. Range Module
- attribute
- 파이썬
- Decorator
- iterator
- Python
- Generator
- 프로그래머스
- Regular Expression
- 30. Substring with Concatenation of All Words
- data science
- 밴픽
- LeetCode
- Python Code
- Convert Sorted List to Binary Search Tree
- 43. Multiply Strings
- Class
- 109. Convert Sorted List to Binary Search Tree
- Python Implementation
- Substring with Concatenation of All Words
- concurrency
- t1
- 시바견
- 운영체제
- 컴퓨터의 구조
- kaggle
- 315. Count of Smaller Numbers After Self
- Protocol
- Today
- Total
목록Decorator (2)
Scribbling
Decorator is a callable that takes another function as its parameter. Decorator is executed during 'import time'. The key idea about closure you must understand is that it can access to 'nonlocal' variables outside the function. Take a look at the below exmaple. def make_averager(): series = [] def averager(new_val): series.append(new_val) return sum(series) / len(series) return averager avg = m..
Decorator는 이미 만든 함수를 수정하지 않고, 함수 주변을 감싸는 방식으로 함수에 추가 기능을 구현한다. def trace(func): # wrapper는 아래처럼 가변 인수로 만들 수 있다. # 가변 인수가 아닌 경우, 원래 함수의 parameter 형태와 일치해야 한다. def wrapper(*args, **kwargs): ret = func(*args, **kwargs) print('{0}(args={1}, kwargs={2}) -> {3}'.format(func.__name__, args, kwargs, ret)) # 원래 함수가 return이 필요한 경우에는 wrapper도 return이 필요하다. return ret return wrapper @trace def get_max(*args..