일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
- Regular Expression
- 715. Range Module
- 43. Multiply Strings
- 컴퓨터의 구조
- 프로그래머스
- attribute
- DWG
- concurrency
- 30. Substring with Concatenation of All Words
- Class
- kaggle
- 시바견
- Python Code
- 파이썬
- 밴픽
- Protocol
- data science
- Substring with Concatenation of All Words
- Convert Sorted List to Binary Search Tree
- Generator
- Python
- iterator
- LeetCode
- 운영체제
- t1
- Python Implementation
- 109. Convert Sorted List to Binary Search Tree
- 315. Count of Smaller Numbers After Self
- shiba
- Decorator
- 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..