Re: how to use more than 1 __init__ constructor in a class ?

2005-06-23 Thread Rocco Moretti
Steven D'Aprano wrote: On Wed, 22 Jun 2005 12:34:21 -0500, Rocco Moretti wrote: You could also turn __init__ into a dispatch fuction: #-- class myPointClass: def __init__(self, *args): if len(args) = 2: self.__init_two(*args) if len(args) == 3:

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-23 Thread Singletoned
Rocco Moretti wrote: Steven D'Aprano wrote: snip That's the joys of a mostly self-taught programming knowledge: you miss out on all the buzzwords. Being mostly self taught myself, I have a tendancy to use infrequently encountered terms in related but technically inappropriate contexts,

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-23 Thread jean-marc
Singletoned wrote: Rocco Moretti wrote: Steven D'Aprano wrote: snip That's the joys of a mostly self-taught programming knowledge: you miss out on all the buzzwords. Being mostly self taught myself, I have a tendancy to use infrequently encountered terms in related but

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-23 Thread Terry Hancock
On Thursday 23 June 2005 10:31 am, Singletoned wrote: Rocco Moretti wrote: Steven D'Aprano wrote: snip That's the joys of a mostly self-taught programming knowledge: you miss out on all the buzzwords. Being mostly self taught myself, I have a tendancy to use infrequently

how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread scott
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

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread Steve
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

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread Michael Hoffman
scott wrote: 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 #-- Well for

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread Paul McGuire
This recipe that I submitted to the Python Cookbook (http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/223611) describes a technique for doing this. I use the example of creating Color objects for plotting to a bitmap, using either R,G,andB values, or a single integer representing the RGB

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread Rocco Moretti
scott 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

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread [EMAIL PROTECTED]
You also could use a list to represent your data, then you get more dimensions supported, e.g: import math class Point: def __init__(self, *args): self.points = list(args) def dist(x, y): if len(x.points) != len(y.points): raise

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread F. Petitjean
Le 22 Jun 2005 11:44:09 -0700, [EMAIL PROTECTED] a écrit : You also could use a list to represent your data, then you get more dimensions supported, e.g: import math class Point: def __init__(self, *args): self.points = list(args) def dist(x, y): if len(x.points)

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread Roy Smith
scott [EMAIL PROTECTED] 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)

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread Jeffrey Maitland
Well one way to do this (not sure if it is the best way) is something like. class mypoint: def __init__(self, *args): len_args = len(args) print len_args if len_args == 0: self.x = 0 self.y = 0 self.z = 0 elif len_args =2 and len_args = 3:

Re: how to use more than 1 __init__ constructor in a class ?

2005-06-22 Thread Steven D'Aprano
On Wed, 22 Jun 2005 12:34:21 -0500, Rocco Moretti wrote: scott wrote: hi people, can someone tell me, how to use a class like that* (or simulate more than 1 constructor) : #-- [snip] You could also turn __init__ into a dispatch fuction: #-- class myPointClass: def