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-September/056786.html below:

[Python-Dev] RFC: readproperty

[Python-Dev] RFC: readproperty [Python-Dev] RFC: readpropertyBarry Warsaw barry at python.org
Thu Sep 29 00:23:15 CEST 2005
On Wed, 2005-09-28 at 10:16, Jim Fulton wrote:

> When we ask for the eggs attribute the first time, we call the
> descriptor, which calls the eggs function.  The function sets the eggs
> attribute, overriding the descriptor. The next time the eggs attribute
> is accessed, the saved value will be used without calling the
> descriptor.
> 
> I do this often enough that I think it would be useful to include it
> in python, either as a builtin (like property) or in the library.  (Or
> possibly by adding an option to property to generate a read
> descriptor.) I'd be happy to add this for 2.5.

I /must/ be missing something.  Why not just use property as a
decorator?

class C:
    @property
    def eggs(self):
        print 'in eggs'
        self.eggs = 7
        return self.eggs

>>> c = C()
>>> c.eggs
in eggs
7
>>> c.eggs
7

-Barry

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 307 bytes
Desc: This is a digitally signed message part
Url : http://mail.python.org/pipermail/python-dev/attachments/20050928/ae8fa9bc/attachment.pgp
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