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/2007-November/075094.html below:

[Python-Dev] Declaring setters with getters

[Python-Dev] Declaring setters with getters [Python-Dev] Declaring setters with gettersTony Lownds tony at PageDNA.com
Thu Nov 1 19:26:52 CET 2007
On Nov 1, 2007, at 10:26 AM, glyph at divmod.com wrote:
> This is a minor nit, as with all decorators that take an argument,  
> it seems like it sets up a hard-to-debug error condition if you were  
> to accidentally forget it:
>
>   @property
>   def foo(): ...
>   @property.set
>   def foo(): ...
>
> would leave you with 'foo' pointing at something that wasn't a  
> descriptor at all.  Is there a way to make that more debuggable?

How about this: give the property instance a method that changes a  
property from read-only to read-write.
No parens, no frame magic. As a small bonus, the setter function would  
not have to be named the same as the
property.

class A(object):
   @property
   def foo(self):
     return 1

   @foo.setter
   def set_foo(self, value):
     print 'set:', value

-Tony

More information about the Python-Dev mailing list

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