2
有没有办法让猴子补丁的核心python类? 东西沿着线:有没有办法让猴子补丁的核心python类?
class Boo:
def is_empty(self) : return not self
list.is_empty = Boo.is_empty
TypeError: can't set attributes of built-in/extension type 'list'
我不想把它扩大,我想猴子修补它。
对不起,我的意思是“猴子补丁”。
你说的“管型”是什么意思?你的意思是“猴子补丁”吗?如果是这样,不,你不能那样做。 – kindall
@ kindall:我认为这是* duck-type *和* duct tape *之间的混合。 –
如果你认为猴子补丁是可能的,但你必须很好地理解CPython的内部结构:https://gist.github.com/mahmoudimus/295200 –