Use
the *args positional-argument to catch all the positional arguments in the
constructor then test them to see what you have and call a kind of sub-init
based on that :
class Point: def
__init__(self,x,y,z):
self.x = x self.y = y self.z = z class
Vector:
def __init__(self,*args): if len(args) == 3: self.setFromValues(args) elif len(args) == 2: if isinstance(args[0],Point): self.setFromPoints(args)
else:
raise "Incorrect
constructor"
print self.i,self.j,self.k def
setFromValues(self,args):
self.i,self.j,self.k = args def
setFromPoints(self,args):
self.i = args[1].x - args[0].x self.j = args[1].y - args[0].y self.k = args[1].z - args[0].z v = Vector(1,2,3)
p1 = Point(2,2,2)
p2 = Point(4,4,4) v2 =
Vector(p1,p2)
Hope this
helps.
-----Original Message-----
From: Jeffrey Maitland [mailto:[EMAIL PROTECTED] Sent: Tuesday, April 05, 2005 10:04 AM To: python-list@python.org Subject: Class, object question.
|
-- http://mail.python.org/mailman/listinfo/python-list