how do i add code to an existing function, either before or after?
for example, i have a class:
class A(object):
def test(self):
print "here"
how do i edit the class wit metaprogramming so that i do this
class A(object):
def test(self):
print "here"
print "and here"
maybe some way of appending another function to test?
add another function such as
def test2(self):
print "and here"
and change the original to
class A(object):
def test(self):
print "here"
self.test2()
is there a way to do this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…