[Tutor] Newbie question on Self, Master and others.
Remco Gerlich
scarblac@pino.selwerd.nl
Sun, 20 Aug 2000 21:30:25 +0200
On Sun, Aug 20, 2000 at 01:52:57PM -0400, FxItAL@aol.com wrote:
> I'm some experiance with VB and am new to Python. In reviewing some code
> examples I've come across the "def __init__()" function with several
> different, what seems to me are argument options. IE: self, master,
> master=None. Would someone explain what these are for and how they are
> Python interprets them.
__init__() is the object's constructor. It's called when the object is
created, to initialize it. Some objects need a few arguments to initialize
itself. The first argument, 'self', is always needed for every method, since
it tells the method for which object it's called.
So in some class
class Spam:
def __init__(self, arg):
self.something = arg
The 'arg' is given to the __init__ function when a new instance is made;
like
instance = Spam("whee") # instance.something is now "whee"
So, in your case the object needs to be handed some "master" object when
to initialize the new instance. What it's for exactly depend on the class
you're talking about, I don't know.
If it says "master = None", that means the argument is optional, and that
master is None if no argument is given.
--
Remco Gerlich, scarblac@pino.selwerd.nl