how to use more than 1 __init__ constructor in a class ?
Steve
lonetwin at gmail.com
Wed Jun 22 13:28:57 EDT 2005
Hi Scott,
> can someone tell me, how to use a class like that* (or "simulate" more
> than 1 constructor) :
One approach could be:
class myPointClass:
def __init__(self, **args):
for k, v in args.items():
setattr(self, k, v)
> *this is not homework
Just to be safe, I'll leave out the explanation :)
Regards
Steve
On 6/22/05, scott <scott at alussinan.org> wrote:
> hi people,
>
> can someone tell me, how to use a class like that* (or "simulate" more
> than 1 constructor) :
> #--
> class myPointClass:
> def __init__(self, x=0, y=0):
> self.x = x
> self.y = y
> def __init__(self, x=0, y=0, z=0):
> self.__init__(self, x, y)
> self.z = z
> #--
>
> tia people
> scott
>
> *this is not homework
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list