U
Uwe Mayer
Hi,
when an instance variable of a class is not found, python tries to fall back
to the class variable.
I want to use that feature to provide default settings for a class which can
be overwritten by assignments to variables with the same name.
This quickly becomes difficult to handle when you get confused wether your
assignment was made to a class variable or an instance variable. I
therefore want to prevent write access to class variables. How do I do
that?
Here some example code:
.... cInt = 5
.... cList = [1,2,3]
.... def __init__(self):
.... self.cInt = 6
....
I tried to overwrite __setattr__(self, name, value) method, but this is only
called if I call it on an instance, i.e.
but not when I call it on the class:
Can anyone give me some pointers or suggentions how to handle this?
Thanks
Uwe
when an instance variable of a class is not found, python tries to fall back
to the class variable.
I want to use that feature to provide default settings for a class which can
be overwritten by assignments to variables with the same name.
This quickly becomes difficult to handle when you get confused wether your
assignment was made to a class variable or an instance variable. I
therefore want to prevent write access to class variables. How do I do
that?
Here some example code:
.... cInt = 5
.... cList = [1,2,3]
.... def __init__(self):
.... self.cInt = 6
....
[1, 2, 5]5
a.cList[2] = 5 #<-- prevent this
a.cList
I tried to overwrite __setattr__(self, name, value) method, but this is only
called if I call it on an instance, i.e.
but not when I call it on the class:
Can anyone give me some pointers or suggentions how to handle this?
Thanks
Uwe