confused about self, why not a reserved word?
Marc Christiansen
usenet at solar-empire.de
Mon May 5 08:28:27 EDT 2008
globalrev <skanemupp at yahoo.se> wrote:
> class Foo(object):
> def Hello(self):
> print "hi"
>
> object is purple, ie some sort of reserved word.
>
> why is self in black(ie a normal word) when it has special powers.
Because `self` is just a name. Using `self` is a convention, but one can
use any name which is not reserved.
> replacing it with sel for example will cause an error when calling
> Hello.
Which error? I don't get one.
0:tolot:/tmp> python f.py
hi
0:tolot:/tmp> cat f.py
class Foo(object):
def Hello(sel):
print "hi"
Foo().Hello()
0:tolot:/tmp>
Marc
More information about the Python-list
mailing list