我正在处理有很多实例变量的类,我想让类继承每个实例变量。像这样:
class foo(object):
def __init__(self,thing1,thing2,thing3,thing4,thing5,thingetc):
self.1 = thing1
self.2 = thing2
self.3 = thing3
self.4 = thing4
self.5 = thing5
self.etc = thingetc
class bar(foo):
self.6 = []
a = bar
print a.3
显然这不管用,但我能在网上找到的所有文档都很混乱。在这种情况下如何继承变量?你知道吗
将此作为继承的模板,重点介绍super()方法:
对于特定类型的类(接受未知数量的初始化参数,即*args):
现在我将亲自使用
**kwargs
over*args
来指定唯一的实例属性:目前,您的代码语法无效,因为数字不能位于变量名的最前面。但是,可以将
*args
与__dict__
一起使用:输出:
相关问题 更多 >
编程相关推荐