【发布时间】:2014-03-10 22:25:48
【问题描述】:
我正在使用 Python 自动化仪器,但我不熟悉使用 Python 进行面向对象编程。我想创建几个类:仪器的超类和控制仪器特定组件(控制器、传感器等)的几个子类
class instrument(object):
def __init__(self):
pass
def function1(self):
print 'Do something'
class component1(instrument):
def __init__(self):
super(component1, self).__init__()
def function2(self):
print 'Do something to component 1'
但是,当我尝试调用 component1 时:
I = instrument()
comp = I.component1()
我得到一个属性错误:
AttributeError: 'instrument' object has no attribute 'component1'
【问题讨论】:
标签: python class subclass attributeerror