A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2007-November/075108.html below:

[Python-Dev] Declaring setters with getters

[Python-Dev] Declaring setters with getters [Python-Dev] Declaring setters with gettersGuido van Rossum guido at python.org
Fri Nov 2 15:19:10 CET 2007
On 11/2/07, Duncan Booth <duncan.booth at suttoncourtenay.org.uk> wrote:
> Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
>
> > Fred Drake wrote:
> >>        @property
> >>        def attribute(self):
> >>            return 42
> >>
> >>        @property.set
> >>        def attribute(self, value):
> >>            self._ignored = value
> >
> > Hmmm... if you were allowed general lvalues as the target of a
> > def, you could write that as
> >
> >    def attribute.set(self, value):
> >      ...
> >
> Dotted names would be sufficient rather than general lvalues.
>
> I like this, I think it looks cleaner than the other options, especially if
> you write both getter and setter in the same style:
>
>     attribute = property()
>
>     def attribute.fget(self):
>         return 42
>
>     def attribute.fset(self, value):
>         self._ignored = value

Sorry, you have just entered Python 4000 territory.

-- 
--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