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/2005-October/057354.html below:

[Python-Dev] Definining properties - a use case for class decorators?

[Python-Dev] Definining properties - a use case for class decorators?Guido van Rossum guido at python.org
Sun Oct 16 17:23:15 CEST 2005
On 10/16/05, Nick Coghlan <ncoghlan at iinet.net.au> wrote:
> On and off, I've been looking for an elegant way to handle properties using
> decorators.
>
> It hasn't really worked, because decorators are inherently single function,
> and properties span multiple functions.
>
> However, it occurred to me that Python already contains a construct for
> grouping multiple related functions together: classes.

Nick, and everybody else trying to find a "solution" for this
"problem", please don't. There's nothing wrong with having the three
accessor methods explicitly in the namespace, it's clear, and probably
less typing (and certainly less indenting!). Just write this:

    class C:
        def getFoo(self): ...
        def setFoo(self): ...
        foo = property(getFoo, setFoo)

--
--Guido van Rossum (home page: http://www.python.org/~guido/)
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