Python add to a function dynamically

前端 未结 7 1404
星月不相逢
星月不相逢 2020-12-08 04:53

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         


        
7条回答
  •  北海茫月
    2020-12-08 05:40

    Why not use inheritance?

    class B(A):
        def test(self):
            super(B, self).test()
            print "and here"
    

提交回复
热议问题