confused about self, why not a reserved word?
J. Cliff Dyer
jcd at unc.edu
Mon May 5 08:51:25 EDT 2008
On Mon, 2008-05-05 at 04:57 -0700, globalrev 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.
> replacing it with sel for example will cause an error when calling
> Hello.
>
Wow. No it won't. sel is perfectly legal. I've seen s used on
occasion, and of course metaclass methods often use cls.
Direct ^C^V from my python interpreter:
$ python
Python 2.4.3 (#1, Dec 11 2006, 11:38:52)
[GCC 4.1.1 20061130 (Red Hat 4.1.1-43)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class Foo(object):
... def Hello(sel):
... print "hi"
...
>>> f = Foo()
>>> f.Hello()
hi
>>>
Can you paste an example that breaks for you?
--
Oook,
J. Cliff Dyer
Carolina Digital Library and Archives
UNC Chapel Hill
More information about the Python-list
mailing list