The need to put "self" in every method

Aahz aahz at pythoncraft.com
Wed Jun 1 15:02:01 EDT 2005


[posted & e-mailed]

In article <wzu0kj9jbi.fsf at ordesa.lan>,
Piet van Oostrum  <piet at cs.uu.nl> wrote:
>
>There is.
>Inside a method there are 3 kinds of identifiers:
>- local ones e.g. parameters and local variables
>- global ones (actually module-level)
>- instance variables and methods
>
>Because Python has no declarations there must be a different way to
>indicate in which category an identifier falls. For globals it is done with
>the 'global' keyword (which actually is a declaration), for instance
>variables the dot notation (object.name) is used and the rest is local.
>Therefore every instance variable or instance method must be used with the
>dot notation, including the ones that belong to the object `itself'. Python
>has chosen that you can use any identifier to indicate the instance, and
>then obviously you must name it somewhere. It could have chosen to use a
>fixed name, like 'this' in Java or C++. It could even have chosen to use a
>keyword 'local' to indicate local ones and let instance ones be the
>default. But if instance variable would be implicit, local ones should have
>been explicit.

Any objection to swiping this for the FAQ?  (Probably with some minor
edits.)
-- 
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

"The only problem with Microsoft is they just have no taste." --Steve Jobs



More information about the Python-list mailing list