[Tutor] self parameter
Benoit Dupire
bdupire@seatech.fau.edu
Thu, 10 May 2001 00:14:43 -0400
By the way, __init__ is a very special method, because it is
automatically called when you create a new object.
To create a new object ( whose class is 'now') you have to do
a= now()
This creates a new object and calls the __init__ method, to initialize
the instance variables (ie. the variables within the object 'a', ie.
self.year, self.month, etc..)
usually , if you want to call a method you have to do:
<name of the object>.<name of the method> ( <parameters>)
so here it would be:
a.__init__( )
Note that this calls the __init__ method substituting 'self' (the
first parameter of the method) with 'a'.
Now on the 'design point-of-view', there is little interest in having a
class 'now'. Why do you want to do objects ?
I think a simple function should do the job, storing your time values in
a list.
Benoit
Katharine Stoner wrote:
> I am trying to understand how special methods work.Ex:class now:
> def _init_(self):
> self.t = time.time()
> self.year, \
> self.month, \
> self.day, \
> self.hour, \
> self.minute, \
> self.second, \
> self.dow, \
> self.doy, \
> self.dst = time.localtime(self.t)I don't know if I got it right,
> but I think the function is passing data to each variable, t; year;
> month; etc. It's unpacking the tuple. I'm not sure I understand how
> this bit of code is working. The self arguement is allowing the
> function to pass data right?I'd much appreciate any
> assistance.-Cameron
--
Benoit Dupire
Graduate Student
----------------
I'd like to buy a new Boomerang. How can i get rid of the old one?