sub typing built in type with common attributes. Am I right?
Peter Otten
__peter__ at web.de
Fri Jul 18 06:05:53 EDT 2008
King wrote:
> My mistake...
> The correct __slots__ is like:
> __slots__ = ['_Attribute_name', '_Attribute_type', '_Attribute_range',
> 'label']
>
> Could you please suggest an alternative or code improvement for the
> matter.
How about
class AttributesMixin(object):
"""Warning: If you change name, type, or range of an existing object
your computer will explode and you will have noone else to blame.
"""
def __init__(self, name=None, type=None, range=None, label=None):
self.name = name
self.type = type
self.range = range
self.label = label
class Float(float, AttributesMixin): pass
class Int(int, AttributesMixin): pass
Now go and write something useful :-)
Peter
More information about the Python-list
mailing list