why self instead obj ?

Jeremy Fincher tweedgeezer at hotmail.com
Thu Mar 6 19:27:09 CET 2003


"Gerard Breiner" <gerard.breiner at ias.u-psud.fr> wrote in message news:<b47r6f$1oo$1 at upsn21.u-psud.fr>...
> I am beginner in Python and i wonder why the first argument of  the__init__
> function is called "self" instead "obj" whereas self  indicates
> the object itself .

It's just a method argument -- if you want to call yours "obj" rather
than self, feel free, it's your choice.

> Moreover, "obj" is easier to type on the keyboard and shorter than "self".

I don't really think this is the case.  On a QWERTY keyboard, self is
a quick four taps of the keyboard, each using a different finger,
three belonging to the home row and one belonging to the
slightly-slower top row.  obj, on the other hand, is three taps of the
keyboard, the first two of which are the same finger, one of those two
is even a ghastly bottom-row-stretch key.  I think if you timed
yourself, you could type self a lot faster and with a lot less strain
than you could type obj.

> Other people would think that "this" is better (as in java), but "obj" seems
> to me more suitable.

I think "self" is the most suitable name because (in most cases) we're
not talking about *any* object, we're talking about the self object. 
We're talking about the instance itself.  "obj" and "this" are both
ambiguous -- we could be referring to any number of objects.  "self",
on the other hand, is explicitly the object being operated upon.

Jeremy




More information about the Python-list mailing list