Newbie Question regarding __init__()

Nat Williams nat.williams at gmail.com
Fri Jul 31 23:13:05 EDT 2009


As MRAB described, ALL instance methods need to accept 'self' as a first
parameter, as that will be passed to them implicitly when they are called.
This includes __init__.  The name 'self' is just a commonly accepted
convention for the name of the instance object passed to methods.  You don't
have to call it that, but you really should.

Take a look at http://docs.python.org/tutorial/classes.html#class-objects
It might help shed some light on how methods and instances work.

One other thing.  I'm a little confused by the first line of
dcObject.__init__:

self.init_Pre() and self.init_Exec()

I suspect this does not do what you think it does.  init_Pre and init_Exec
will both be called by this expression (unless init_Pre throws an exception,
of course).  You're not getting anything here that you wouldn't by just
calling each method on a separate line, except just making it harder to
read.

Nat


On Fri, Jul 31, 2009 at 8:53 PM, Simon <dciphercomputing at gmail.com> wrote:

> Hi
>
> So should the dcObject class include the "self" as well since I have
> not defined an __init__ method in dcCursor?
>
> Simon
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090731/3f9a41d4/attachment-0001.html>


More information about the Python-list mailing list