tag:blogger.com,1999:blog-18508356.post8975919509166303367..comments2023-05-21T09:53:50.042-04:00Comments on Just a little Python: Lazy DescriptorsRick Copelandhttp://www.blogger.com/profile/11612114223288841087noreply@blogger.comBlogger14125tag:blogger.com,1999:blog-18508356.post-49417755133924003912010-10-01T09:25:45.691-04:002010-10-01T09:25:45.691-04:00It looks like these days this pattern is available...It looks like these days this pattern is available in zope.cachedescriptors (which can be installed from pypi independently of zope) as property.Lazy: <a href="http://pypi.python.org/pypi/zope.cachedescriptors#lazy-computed-attributes" rel="nofollow">http://pypi.python.org/pypi/zope.cachedescriptors#lazy-computed-attributes</a>piahwefhttps://www.blogger.com/profile/14301480369336177718noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-43561659337360925112010-09-13T20:16:11.537-04:002010-09-13T20:16:11.537-04:00interesting take nice solutioninteresting take nice solutionblu rayhttp://bestblurayplayerinfo.net/noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-83203984983207371642010-02-02T00:45:54.150-05:002010-02-02T00:45:54.150-05:00Rick I just ran across this post by accident. Thi...Rick I just ran across this post by accident. This is indeed an elegant pattern. Thanks for posting.Noah Gifthttps://www.blogger.com/profile/13144332122855013229noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-53367496876273912462009-12-07T04:46:00.916-05:002009-12-07T04:46:00.916-05:00thumbs up! a very elegant pattern.thumbs up! a very elegant pattern.Yonatan Pnoreply@blogger.comtag:blogger.com,1999:blog-18508356.post-23143073100689593602009-02-13T07:18:00.000-05:002009-02-13T07:18:00.000-05:00ahhh.. it used my very very old profile to post my...ahhh.. it used my very very old profile to post my comment.... grrrr<BR/><BR/>drop me a comment in livingubuntu.com or an email to alfredodeza (at) gmail.comAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-18508356.post-63775141670861709402009-02-13T07:16:00.000-05:002009-02-13T07:16:00.000-05:00rick, I watched your presentation last night but h...rick, I watched your presentation last night but had to leave early.<BR/><BR/>Would love to offer my help with Clutch.<BR/><BR/>Let me know what can I do to help out.Alfredohttps://www.blogger.com/profile/08016450579416106877noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-49802813555465513312008-08-24T20:27:00.000-04:002008-08-24T20:27:00.000-04:00I'm really excited to use this. Maybe sometime thi...I'm really excited to use this. Maybe sometime this week in Algebra or Geometry class. ;)Adriennehttps://www.blogger.com/profile/10885019938041824698noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-60300335914939847652008-08-24T14:16:00.000-04:002008-08-24T14:16:00.000-04:00@ronny:Thanks for the pointers. I have updated th...@ronny:<BR/><BR/>Thanks for the pointers. I have updated the post to reflect your changes.<BR/><BR/>@anonymous:<BR/>With the changes suggested by ronny, a function is no longer called on each attribute access (technically, it wasn't being called before, I just had an extraneous check of the object's __dict__).Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-20719215870515279512008-08-24T11:39:00.000-04:002008-08-24T11:39:00.000-04:00you don't need to check if the attribute slot is o...you don't need to check if the attribute slot is on the instance<BR/><BR/>non-data descriptors get overridden by instance attributes<BR/><BR/>also please copy the name to __name__ and the documentation to __doc__<BR/><BR/>so its more easy to use with the common introspection toolsRonnyPfannschmidthttps://www.blogger.com/profile/06295961645811499445noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-24002625621287602702008-08-23T10:05:00.000-04:002008-08-23T10:05:00.000-04:00@doug:Yup, you guessed it. In particular, I wante...@doug:<BR/>Yup, you guessed it. In particular, I wanted an ORM-mapped object as an attribute on a TurboGears controller.Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-22579189809796556222008-08-23T10:03:00.000-04:002008-08-23T10:03:00.000-04:00@anonymous:Actually, I didn't invent the name "des...@anonymous:<BR/>Actually, I didn't invent the name "descriptor" -- it's Python terminology <A HREF="http://docs.python.org/ref/descriptors.html" REL="nofollow">documented here</A>. I probably should have given more context in the post. As for a function being called every time, yes, that still happens, but the (potentially expensive) <I>calculation</I> of the value of bar only happens once.Rick Copelandhttps://www.blogger.com/profile/11612114223288841087noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-84290096350560231492008-08-23T07:52:00.000-04:002008-08-23T07:52:00.000-04:00That looks like a good way to defer object retriev...That looks like a good way to defer object retrieval from a database.Doug Hellmannhttps://www.blogger.com/profile/01892352754222143463noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-54308208174992960702008-08-23T07:37:00.000-04:002008-08-23T07:37:00.000-04:00Mate, Great post. I wish you had posted this a ...Mate,<BR/><BR/> Great post. I wish you had posted this a month earlier :D. I had stumbled upon this in django (in the django.contrib.auth.middleware.py). It does just the thing to obtain access to the user object on a request.<BR/><BR/>But keep em coming mate, keep em coming.<BR/><BR/>Cheers<BR/>SriUnknownhttps://www.blogger.com/profile/14773524828641281870noreply@blogger.comtag:blogger.com,1999:blog-18508356.post-39479777527920019622008-08-23T06:28:00.000-04:002008-08-23T06:28:00.000-04:00I'm too lazy to try to understand how this thing w...I'm too lazy to try to understand how this thing works, what it does, and ramifications... but your naming it "descriptor", uh, woot?<BR/><BR/>http://foldoc.org/foldoc.cgi?query=descriptor<BR/><BR/>And isn't a function called _every_ time anyway?Anonymousnoreply@blogger.com