[Python-Dev] RFC: readproperty
Barry 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