Python: replacing a function within a class of a module

后端 未结 3 1194
遥遥无期
遥遥无期 2020-12-13 11:35

I\'m trying to replace a function defined within a class in order to modify its function (as in inner workings) without changing the actual code. I\'ve never done this befor

3条回答
  •  轮回少年
    2020-12-13 11:49

    check class inheritance in python, to create your own custom class:

    from somemodule import TestMOD
    
    class YourCustomClass(TestMOD):
    
        # change the function
        def test_func(self, variable):
            #
            #
    
    your_class = YourCustomClass()
    your_class.test_func(x)
    

提交回复
热议问题