From: Ron A. <rr...@ro...> - 2008-02-07 02:00:44
|
bre...@un... wrote: > > Interesting and a nice "refactoring". Thanks :-) > I just started with vPython (but already know Python somewhat) and > assumed that to create groups one would derive classes from frame, as > shown. It seems to work, but is this not preferred/robust? > > import visual as v > > class Wheelset(*v.frame*): > > def __init__(self, xPos, whlRad=0.5, /etc/): > > *v.frame.__init__(self,* pos=(xPos,whlRad,0.0)*)* > > v.cylinder(*frame=self*, pos=(0,0,-0.5*axleLength), > axis=(0.0, 0.0, axleLength), radius=axlRad) > etc When I tried a variation of the above with the Head() object, the class color attribute was overwritten. The defaults could be moved to within the __init__ method, but then you may have the opposite problem of overwriting a frame attribute or method without knowing it. So I think if there are a lot of methods or attributes, using a container obj makes it easier to avoid name clashes. But it looks like, either way is ok. Ron |