help needed for used linalg package used by blam

At this link http://users.rcn.com/python/download/python.htm python implemented linalg and is used by blam http://code.google.com/p/blam/wiki/UsersGuide

So now my Python problem look at the code, the diveision is ‘my’ problem, example after the code :evilgrin:


.... #help def's ... not needed
class Table(list):
    dim = 1
    concat = list.__add__      # A substitute for the overridden __add__ method
    def __getslice__( self, i, j ):
        return self.__class__( list.__getslice__(self,i,j) )
    def __init__( self, elems ):
        list.__init__( self, elems )
#        print("
PKHG.DBG====== type and elems",type(elems),elems)
        elems = [el for el in elems] #PKHG for Python 3.2
        if len(elems) and hasattr(elems[0], 'dim'): self.dim = elems[0].dim + 1
    def __str__( self ):
        return separator[self.dim].join( map(str, self) )
    def map( self, op, rhs=None ):
        '''Apply a unary operator to every element in the matrix or a binary operator to corresponding
        elements in two arrays.  If the dimensions are different, broadcast the smaller dimension over
        the larger (i.e. match a scalar to every element in a vector or a vector to a matrix).'''
        if rhs is None:                                                 # Unary case
            return self.dim==1 and self.__class__( map(op, self) ) or self.__class__( [elem.map(op) for elem in self] )
        elif not hasattr(rhs,'dim'):                                    # List / Scalar op
            return self.__class__( [op(e,rhs) for e in self] )
        elif self.dim == rhs.dim:                                       # Same level Vec / Vec or Matrix / Matrix
            assert NPRE or len(self) == len(rhs), 'Table operation requires len sizes to agree'
            return self.__class__( map(op, self, rhs) )
        elif self.dim < rhs.dim:                                        # Vec / Matrix
            return self.__class__( [op(self,e) for e in rhs]  )
        return self.__class__( [op(e,rhs) for e in self] )         # Matrix / Vec
    def __mul__( self, rhs ):  return self.map( operator.mul, rhs )
    def __div__( self, rhs ):  return self.map( operator.div, rhs )
    def __sub__( self, rhs ):  return self.map( operator.sub, rhs )
    def __add__( self, rhs ):  return self.map( operator.add, rhs )
    def __rmul__( self, lhs ):  return self*lhs
    def __rdiv__( self, lhs ):  return self*(1.0/lhs)

The division rdiv is in blam NOT used: # before that line!
Reason this code does not work in Blender with Python 3.2
one gets this error:
TypeError: unsupported operand type(s) for /: ‘Table_orig’ and ‘float’
and replace ‘float’ by int if one tries to devide by an integer

replacing (if a is an table) a / 3 by a * (1.0/3) all table elements are ‘divided’ by 3
so a possible solution but …

QUESTION:
How to program the division (maybe with a test of denominator 0) ???

In Blam that division is not used (available)
It is just Python insufficient knowledge of me … and am curious to know how this could be done in Python 3.2 …

Solved:
truediv solves my problem :wink: