[Tutor] sorting objects with embedded data

Doug Stanfield DOUGS@oceanic.com
Tue, 15 Aug 2000 08:08:10 -1000

I can give part of a possible answer.  I'd point you in the direction of
setting up a subclass for the cube object.  You might explore if the work is
already done or being done, but it would make sense that there was a __cmp__
method of the object that would rank two cubes correctly.  You probably also
have to implement some of the other magic methods (gurus please pipe up
here) such as __getattr__.

If subclassing 'cube' isn't working, creating a 'cubes' class that would
encapsulate the sort behaviour probably is the way to go.  Maybe subclassing
UserList as a start.

Hope this helps,


> -----Original Message-----
> From: michaelbaker@operamail.com [mailto:michaelbaker@operamail.com]
> Sent: Tuesday, August 15, 2000 7:36 AM
> To: tutor@python.org
> Subject: [Tutor] sorting objects with embedded data
> I'm using python with blender (http://www.blender.nl) - an 
> amazing freeware
> 3d modeling and animation package. I'm trying to sort a bunch 
> of objects
> based on their positions in the Z axis direction. 
> example:
> cubes=[[cube.001],[cube.002],[cube.003],[cube.004],[cube.005]]
> # each cube object contains coordinate data accessible through 3 
> # methods? LocX, LocY, LocZ - these correspond to the x, y and 
> # z axes respectively. Here's what I've got:
> buffer=[]
> for a in cubes:
> 	buffer.append(a.LocZ)
> buffer.sort()
> # this returns a sorted list of z coordinate values - great, but I 
> # need to access the x and y coordinate data based on the sorted z 
> # data - now I need to sort the cubes list based on the sorting 
> # of the buffer list. 
> # Is it possible to sort the cubes list in-place based on the 
> # embedded LocZ numerical data? 
> thanks in advance - check out blender, it's amazing.
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://www.python.org/mailman/listinfo/tutor