forked from faif/python-patterns
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecorator.py
More file actions
Latest commit
21 lines (18 loc) · 507 Bytes
/
Copy pathdecorator.py
File metadata and controls
21 lines (18 loc) · 507 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# http://stackoverflow.com/questions/3118929/implementing-the-decorator-pattern-in-python
classfoo(object):
deff1(self):
print("original f1")
deff2(self):
print("original f2")
classfoo_decorator(object):
def__init__(self, decoratee):
self._decoratee=decoratee
deff1(self):
print("decorated f1")
self._decoratee.f1()
def__getattr__(self, name):
returngetattr(self._decoratee, name)
u=foo()
v=foo_decorator(u)
v.f1()
v.f2()