What is monkey patching?

前端 未结 8 2031
[愿得一人]
[愿得一人] 2020-11-21 16:35

I am trying to understand, what is monkey patching or a monkey patch?

Is that something like methods/operators overloading or delegating?

Does it have anyt

8条回答
  •  悲&欢浪女
    2020-11-21 17:21

    A MonkeyPatch is a piece of Python code which extends or modifies other code at runtime (typically at startup).

    A simple example looks like this:

    from SomeOtherProduct.SomeModule import SomeClass
    
    def speak(self):
        return "ook ook eee eee eee!"
    
    SomeClass.speak = speak
    

    Source: MonkeyPatch page on Zope wiki.

提交回复
热议问题