How does one monkey patch a function in python?

前端 未结 5 1687
没有蜡笔的小新
没有蜡笔的小新 2020-11-29 19:58

I\'m having trouble replacing a function from a different module with another function and it\'s driving me crazy.

Let\'s say I have a module bar.py that looks like

5条回答
  •  被撕碎了的回忆
    2020-11-29 20:16

    There's a really elegant decorator for this: Guido van Rossum: Python-Dev list: Monkeypatching Idioms.

    There's also the dectools package, which I saw an PyCon 2010, which may be able to be used in this context too, but that might actually go the other way (monkeypatching at the method declarative level... where you're not)

提交回复
热议问题