ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-list
python-list
RE: what is self?
by Michael Chermside other posts by this author
Jul 2 2003 10:55PM messages near this date
i18n worries | Signal-handling question
paul h writes:
   [...]
>  looking into the code, i see a lot of references to "self" ie
>  self.window = ...
   [...]

In Python, "self" is nothing special at all... it's just a normal
variable like "x" or "y" or "myObject". If you look at the top of
the method declaration where you saw self used, you'll see that
"self" is the name of the first argument.

What's different now is that you're starting to use objects. When
you use objects in Python, they have functions that belong to the
objects themselves (called "methods"). In Python, the first
argument to any method (a function defined within a class) will
always be the particular object on which the method is being
called. Since that first argument always means "the object this
method is called on" Python programmers nearly always use the
same name for it... and "self" happens to be the conventional name.

Everything would work just fine if you changed "self" to "abc" in
the parameter list and also within the body of the method. 
Everything, that is, except for the fact that people reading your
code would find it a bit odd and confusing.

-- Michael Chermside



-- 
http://mail.python.org/mailman/listinfo/python-list

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved