structs in python

Opus opus at value.net
Sun Jul 7 06:58:13 EDT 2002


And the __slots__ way is strange if you are using the __variables in your 
class.

class thing(object):
  __slots__ = ["_thing__var"]		# Huh???
  def __init__(self,init):
    self.__var = init

For the point idea, the typo there would have been caught in the compile time.  
And, doing the delta actually makes much more sense overloading __sub__ for the 
point class.  

class Point(object):
  def __init__(self,x,y,color):
    self.x=x
    self.y=y
    self.color = color
  def __sub__(self,other):
    return Point(self.X-other.X, self.Y-other.Y, self.color-other.color)

True, this is some code to create, but because it is something that is not 
going to be used that often, it means that you control the way it is done in 
one place and you don't have to remember, or research how to do it everytime 
you use it.  And, yes, I have used classes in C++ as structs, and I remember 
that it was the prefered way to handle structs.

On 6 Jul 2002 at 23:30, Paul Rubin wrote:

> "Sean 'Shaleh' Perry" <shalehperry at attbi.com> writes:
> > However this breaks down for your delta = ... example.
> > 
> > is
> > 
> > class Point:
> >   def __init__(x, y, color):
> >     self.x = x
> >     self.y = y
> >     self.color = color
> > 
> > really that much to type?
> 
> Yes, it seems clumsy to me.  See how error prone it is: your __init__
> function arg list forgot to mention 'self'.
> 
> The new slots scheme may be better but it doesn't exist in older
> Pythons and isn't well documented in 2.2.
> -- 
> http://mail.python.org/mailman/listinfo/python-list


--Opus--

Eagles may soar, but weasels don't get sucked into jet engines.
				- Unknown

--------------------------------------------------------
Get added to my Humor list:
mailto:opus at value.net?subject=ADD_HUMOR
Get added to my Neat list:
mailto:opus at value.net?subject=ADD_NEAT
Get my PGP public key:
mailto:opus at value.net?subject=PSEND&body=send%20PublicKEY.asc
Visit My Home Page:
http://value.net/~opus/








More information about the Python-list mailing list