[Python-Dev] read-only properties
jrw at pobox.com
Tue Oct 8 22:45:15 CEST 2002
Guido van Rossum wrote:
>>The key seems to be that property() doesn't know the name the
> Oops, you're right. This makes it practically impossible to improve
> the error message (without the kind of trick that Jeff shows).
> --Guido van Rossum (home page: http://www.python.org/~guido/)
> Python-Dev mailing list
> Python-Dev at python.org
Why not have the property find its name in the class's __dict__,
something like this:
(in class property)
def __set__(self, obj, value):
if self.fset is not None:
for key, value in type(obj).__dict__.iteritems():
if value is self:
raise AttributeError, "Property '" + key + "' is read-only."
# No name? Strange put possible I guess.
raise AttributeError, "can't set property"
More information about the Python-list