| owl_the_first FuncCount 8316 | Закс Роберт, 503 группа FuncCount 7938 | ||||
|---|---|---|---|---|---|
| f | 1 | from functools import wraps | f | 1 | from functools import wraps |
| 2 | 2 | ||||
| n | 3 | def counter(f): | n | 3 | def counter(func): |
| 4 | count = 0 | 4 | count = 0 | ||
| 5 | 5 | ||||
| n | 6 | @wraps(f) | n | 6 | @wraps(func) |
| 7 | def wrapper(*args, **kwargs): | 7 | def wrapper(*args, **kwargs): | ||
| 8 | nonlocal count | 8 | nonlocal count | ||
| 9 | count += 1 | 9 | count += 1 | ||
| n | 10 | return f(*args, **kwargs) | n | 10 | return func(*args, **kwargs) |
| 11 | 11 | ||||
| n | 12 | def get(): | n | 12 | def counter_method(): |
| 13 | nonlocal count | 13 | nonlocal count | ||
| 14 | return count | 14 | return count | ||
| t | 15 | wrapper.counter = get | t | 15 | wrapper.counter = counter_method |
| 16 | return wrapper | 16 | return wrapper | ||
| Legends | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
| |||||||||