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 –