howto prevent class variable assignment

Gerrit Holl gerrit at nl.linux.org
Sun Feb 1 09:48:02 EST 2004


Uwe Mayer wrote:
> 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?

I think you can do that with a Metaclass.
See http://www.python.org/2.2.2/descrintro.html#metaclasses

Gerrit.

-- 
Public key:
http://people.nl.linux.org/~gerrit/gpg_public_key
-- 
PrePEP: Builtin path type
    http://people.nl.linux.org/~gerrit/creaties/path/pep-xxxx.html
Asperger's Syndrome - a personal approach:
	http://people.nl.linux.org/~gerrit/english/




More information about the Python-list mailing list