A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2002-October/029406.html below:

[Python-Dev] read-only properties

[Python-Dev] read-only properties [Python-Dev] read-only propertiesJohn Williams jrw@pobox.com
Tue, 08 Oct 2002 17:34:05 -0500
Guido van Rossum wrote:
>>The key seems to be that property() doesn't know the name the
>>property has.
> 
> 
> 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@python.org
> http://mail.python.org/mailman/listinfo/python-dev

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:
       self.fset(obj, value)
     else:
       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"




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4