blob: 38be54603c9dc7876e5d75a83f6c668a981e70dc (
plain)
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
|
# chatty2.py
import customdec; customdec.enhance_classes()
# sets the log files
log1=file('file1.log','w')
log2=file('file2.log','w')
class C:
"[Decorated]"
def f(self):
"[chattymethod2]"
f.logfile=log1 # function attribute
def g(self):
"[chattymethod2]"
g.logfile=log2 # function attribute
assert C.__dict__['f'].logfile is log1 # check the conversion
assert C.__dict__['g'].logfile is log2 # function attr. -> decorator attr.
c=C() # C instantiation
c.f() # print a message in file1.log
c.g() # print a message in file2.log
log1.close(); log2.close() # finally
|