A
Alaric Haag
Hello,
Is the use of __repr__ below a "really bad idea"?
class Dimension():
def __init__(self, setp, name):
ptr = setp.contents.dim
while ptr.contents.name != name:
ptr = ptr.contents.next
self.name = ptr.contents.name
self.size = ptr.contents.size
self.unlimited = bool(ptr.contents.unlimited)
self.coord = ptr.contents.coord
def __repr__(self):
return '%g' % (self.size)
As written, if a program references a Dimension instance without an
attribute, it gets the size attrbute "by default". If it wants the other
attributes, they have to be spec'd. In the context of the code being
developed, the "size" attribute is the "logical" representation of the
dimension. I'm just wondering if this sort of design should be avoided.
Many thanks!
Alaric
Is the use of __repr__ below a "really bad idea"?
class Dimension():
def __init__(self, setp, name):
ptr = setp.contents.dim
while ptr.contents.name != name:
ptr = ptr.contents.next
self.name = ptr.contents.name
self.size = ptr.contents.size
self.unlimited = bool(ptr.contents.unlimited)
self.coord = ptr.contents.coord
def __repr__(self):
return '%g' % (self.size)
As written, if a program references a Dimension instance without an
attribute, it gets the size attrbute "by default". If it wants the other
attributes, they have to be spec'd. In the context of the code being
developed, the "size" attribute is the "logical" representation of the
dimension. I'm just wondering if this sort of design should be avoided.
Many thanks!
Alaric