Extension methods in Python

后端 未结 6 1027
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 01:55

Does Python have extension methods like C#? Is it possible to call a method like:

MyRandomMethod()

on existing types like int?

6条回答
  •  半阙折子戏
    2021-01-31 02:36

    Another option is to override the meta-class. This allows you to, among other things, specify functions that should exist in all classes.

    This article starts to discuss it:

    http://www.onlamp.com/pub/a/python/2003/04/17/metaclasses.html

提交回复
热议问题