S
Steven Bethard
bruno said:Yes there are:
object.name is public
object._name is protected
object.__name is private
The double-underscore name-mangling is almost never worth it. It's
supposed to stop name collisions, but, while it does in some cases, it
doesn't in all cases, so you shouldn't rely on this. For example:
---------- mod1.py ----------
class C(object):
__x = 'mod1.C'
@classmethod
def getx(cls):
return cls.__x
-----------------------------
---------- mod2.py ----------
import mod1
class C(mod1.C):
__x = 'mod2.C'
-----------------------------
py> import mod1, mod2
py> mod1.C.getx()
'mod1.C'
py> mod2.C.getx()
'mod2.C'
If double-underscore name-mangling worked like private variables,
setting C.__x in mod2.C should not affect the value of C.__x in mod1.C.
STeVe