Python extension methods

后端 未结 7 1933
星月不相逢
星月不相逢 2021-02-02 06:39

OK, in C# we have something like:

public static string Destroy(this string s) { 
    return \"\";
}

So basically, when you have a string you ca

7条回答
  •  不知归路
    2021-02-02 07:22

    You can do what you have asked like the following:

    def extension_method(self):
        #do stuff
    class.extension_method = extension_method
    

提交回复
热议问题