python中的monkey-patching

这个技巧我很少用过。 但知道无防。 在运行时改变函数或类的行为, 一般用猴子补丁,原类,装饰器都可以实现。 #!/usr/bin/env python # -*- coding: utf-8 -*- import types class Class(object): def add(self, x, y): return x + y inst = Class() def
相关文章
相关标签/搜索