【发布时间】:2019-11-14 14:10:22
【问题描述】:
假设我有一个类Test,其属性为names,方法为calculate。
class Test:
def __init__(self, names=('square', 'cube')):
self.names = names
def calculate(self, x):
return x**2, x**3
是否有一种简单的方法可以确定传递的名称数量等于calculate 返回的值的(可变)数量,而无需实际通过该方法传递数据?基本上我只想要求类定义在实现时是一致的。
类似于额外的一行:
# check that calculate output and names line up
# help needed here
assert len(self.names) == # length of output of self.calculate
【问题讨论】:
标签: python-3.x oop inspect