[Python-Dev] RFC: readproperty

Guido van Rossum guido at python.org
Thu Sep 29 01:09:36 CEST 2005


It doesn't work that way for new-style classes.

On 9/28/05, Barry Warsaw <barry at python.org> wrote:
> 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
>
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.1 (GNU/Linux)
>
> iQCVAwUAQzsX03EjvBPtnXfVAQK43QP/dRjW11myDXRdjXcPPuaxRQ2qtUlMyAJG
> 26sedhmrF00rvKVh7U0RaGJ/Cq5iwgEbQRmXm1pbS8UKzNZxz55qGjVDXjp7Rwgr
> KJpJzz/UWVqVClRJJGDdgasRO8GUfxTYh2YPrmXaTDPLh3uscIwpwq1oapT1R4OH
> 6xJYLrjAs9M=
> =mCyw
> -----END PGP SIGNATURE-----
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> http://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
>
>
>


--
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-Dev mailing list