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:
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,
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
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
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
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
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
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
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
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
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)
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)
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:
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
14 matches
Mail list logo