list as an instance attribute

r rt8396 at gmail.com
Mon Sep 14 03:31:20 EDT 2009


On Sep 13, 7:34 pm, Daniel Santos <daniel.d... at gmail.com> wrote:
> Here goes,
>
> I have a base class that is the following :
>
> class primitive:
>
>         def __init__(self):
>                 self.name = ""
>                 self.transforms = []
>
>         def copyInternalState(self, sourceObj, copyName):
>                 return null
>
>         def copy(self, copyName):
>
>                 # copy the source object internal state
>                 primitiveCopy = self.copyInternalState(self, copyName)
>
>                 # copy the transformations
>                 primitiveCopy.transforms = []
>
>                 if self.transforms != []:
>                         for transf in self.transforms:
>                                 primitiveCopy.transforms.append(transf.copy())
>
>                 return primitiveCopy
>
>         # more methods. the ones listed should be enough to get the picture
>
> And a derived class,
>
> class CircularCilinder(primitive):
>
>         def __init__(self, name):
>
>                 self.name = name
>                 self.baseCenterVertex = [0, 0, 0]
>                 self.heightVertex = [0, 1, 0]
>                 self.radius = 1
>
>         def copyInternalState(self, sourceObj, copyName):
>
>                 copy = CircularCilinder(copyName)
>
>                 copy.setHeight(self.heightVertex[1])
>                 copy.setRadius(self.radius)
>
>                 return copy
>


You never initialized Primitive in CCylinder! And always write class
names with an initial uppercase letter...
class Primitive():
   def...




More information about the Python-list mailing list