具有常量继承的类

时间:2015-08-08 15:10:22

标签: python inheritance

对于Python中的gpib设备接口(使用ctypes模块),我将此设备在我的类中使用的常量分组:

class IbcnfOPTConst(object):
    ''' 
    The following constants are used for the second parameter of the  ibconfig() function.
    They are the "option" selection codes.
    '''
    IbcPAD             = 0x0001  #// Primary Address
    IbcSAD             = 0x0002  #// Secondary Address
    IbcTMO             = 0x0003  #// Timeout Value
    IbcEOT             = 0x0004  #// Send EOI with last data byte?
    ...

另一个函数需要几乎相同的常量但是用新的常量更新,旧的函数现在有不同的含义,所以我将一个新类定义为现有的继承:

class IbAskConst(IbcnfOPTConst):
    ''' Constants that can be used 
        when calling the ibask() function.
    '''
    IbaPAD             = IbcnfOPTConst.IbaSAD
    IbaTMO             = IbcnfOPTConst.IbcTMO
    IbaEOT             = IbcnfOPTConst.IbcEOT
    IbaPPC             = IbcnfOPTConst.IbcPPC
    ....
    IbaSerialNumber    = 0x0023
    IbaBNA             = 0x0200  #// A device's access board

继承在子类中使用常量是否有更好的方法?

0 个答案:

没有答案