Newbie Q: Class Privacy (or lack of)
Steve Jobless
sjobless at rotten.apple.commie
Mon Jul 24 22:49:06 EDT 2006
Hi,
I just started learning Python. I went through most of the tutorial at
python.org. But I noticed something weird. I'm not talking about the
__private hack.
Let's say the class is defined as:
class MyClass:
def __init__(self):
pass
def func(self):
return 123
But from the outside of the class my interpreter let me do:
x = MyClass()
x.instance_var_not_defined_in_the_class = 456
or even:
x.func = 789
After "x.func = 789", the function is totally shot.
Are these bugs or features? If they are features, don't they create
problems as the project gets larger?
TIA,
SJ
More information about the Python-list
mailing list