问题描述
我正在编写一些小型库,我想通过实例方法和静态方法为用户提供两种实现相同功能的方法。这是一个简化的示例:
class ClasstimesAdd(object):
def __init__(self,a,b):
self.a = a
self.b = b
def TimesAdd(self,c):
return self.a * self.b + c
@staticmethod
def TimesAdd(a,b,c):
return a * b + c
print(ClasstimesAdd.TimesAdd(1,3,7))
ins = ClasstimesAdd(2,5)
print(ins.TimesAdd(7))
您会发现较早的功能将被覆盖,只有最后一个有效。我想知道是否有一些简单的方法可以使两种方法都起作用。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)