Why self?
Bo M. Maryniuck
b.maryniuk at forbis.lt
Tue Jul 9 03:44:28 EDT 2002
On Monday 08 July 2002 21:27, Brian Quinlan wrote:
> Two leading underscores make the instance variable private.
And only for this... Actually they are not private as they should be. :)
-----------------8<-----------------
class stuff:
def __init__(self):
self.bar = 'bar'
self.__baz = 'baz'
__spam = 'spam'
stf = stuff()
print stf.bar
print stf._stuff__baz
print dir(stf)
-----------------8<-----------------
Prints this:
-----------------8<-----------------
bar
baz
['_stuff__baz', 'bar']
-----------------8<-----------------
May be it is possible to access even __spam variable somehow...
> Python forces you to be explicit. That way we will know what you are
> doing, right or wrong.
That what I love Python -- C/C++ is very "buggy". :)
--
Sincerely yours, Bogdan M. Maryniuck
"Linux poses a real challenge for those with a taste for late-night
hacking (and/or conversations with God)."
(By Matt Welsh)
More information about the Python-list
mailing list