How To capture an id into an array..
Balaji
balaji at email.arizona.edu
Mon Mar 29 12:32:42 EST 2004
Thanks for all the initial help....
Sorry for bugging you again...
Here is a part of my code..
Suppose if some body wants to assign an e=E() to an expression class..
he may define then e=v+v1(where v and v1 both belong to a variable class)
now again if we define say v2=V() and then try to multiply v2 with e then I want
to raise an error that it is a nonlinear term..
So what I though was if i keep track of all the instances id then I might raise
an exception...
But the problem was i couldnt check the right side of an assigment...
Can the right side of an assignment be checked...
class E:
def __init__(self):
print "E",id(self)
def __add__(self,e2):
e = E()
e.operator = '+'
e.left = self
e.right = e2
return e
def __sub__(self,e2):
e = E()
e.operator = '-'
e.left = self
e.right = e2
return e
def __mul__(self,m2):
e = E()
e.operator = '*'
e.left = self
e.right = m2
return e
def __div__(self,d1):
e = E()
e.operator = '/'
e.left = self
e.right = d1
return e
def __str__(self):
return str(self.left) + self.operator + str(self.right)
check=[]
class V(E):
""" This is a variable for MPY"""
def __init__(self):
print id(self)
check.append(id(self))
self.val = None
def __mul__(self,m2):
e=E()
if self.__class__ == m2.__class__:
return "non"
else:
e=E()
e.operator = '*'
e.left = self
e.right = m2
return e
--- Balaji
More information about the Python-list
mailing list