|
|
|
|
|
by hermitdev
35 days ago
|
|
> Python is harder to JIT because of the way __dict__ works. Heh, how about how `__class__` works? Not that I recommend actually doing this, but you can literally change the type of an already instantiated object by reassigning `__class__`: >>> class Dog:
... def hi(self):
... print("woof")
...
>>> class Cat:
... def hi(self):
... print("meow")
...
>>> dog = Dog()
>>> dog.hi()
woof
>>> dog.__class__ = Cat
>>> dog.hi()
meow
>>> isinstance(dog, Dog)
False
>>> isinstance(dog, Cat)
True
>>>
|
|