classes and __init__ question

Alex Hall mehgcap at gmail.com
Mon May 17 16:19:59 EDT 2010


Hi all,
I am a bit confused about classes. What do you pass a class, since all
the actual information is passed to __init__? For example, say you
have a dog class. The dog object has a name, a size, and a color. I
believe you would say this:

class dog():
 def __init__(self, name, size, color):
  self.name=name
  self.size=size
  self.color=color
 #end def
#end class

What, then, gets passed to the class constructor?
class dog(whatGoesHere?):
Sometimes I see things passed to this. For example, if you create a
class for a wxPython frame, you will say:
class myapp(wx.App):
In this case you pass something. However, I have a class that I use in
one of my programs to create "contact" objects, which looks like this:
class contact():
 def __init__(self, name, email, status, service):
  self.name=name
  self.email=email
  self.status=status
  self.service=service
 #end def
#end class

Here, I do not pass anything to the class, only to __init__. What is going on?

On a related note, is it horrible for resource usage to create a large
array, up to 500 or so, where each member is a small object? I am
thinking of, for example, a game board array where each member of the
array is a "square" object. A square might have a status, a color, and
other flags associated with it, so you could then say something like
board[i][j].hasGamePiece=True. Lookups and adjustments like this will
be going on a lot. Am I better off using an array of numbers where
each number means something different?

Thanks in advance for any info.


-- 
Have a great day,
Alex (msg sent from GMail website)
mehgcap at gmail.com; http://www.facebook.com/mehgcap



More information about the Python-list mailing list