在Python中修改不可变类型的__new__属性

use*_*011 -1 python

我试图修改Python中'int'类型的行为.

它说

'__new__' is readonly.

有办法吗?

谢谢.

Sve*_*ach 5

您无法修改内置类型,但可以从中派生:

 class MyInt(int):
     def __new__(cls, *args):
         # whatever
Run Code Online (Sandbox Code Playgroud)