addressalign-toparrow-leftarrow-rightbackbellblockcalendarcameraccwcheckchevron-downchevron-leftchevron-rightchevron-small-downchevron-small-leftchevron-small-rightchevron-small-upchevron-upcircle-with-checkcircle-with-crosscircle-with-pluscontroller-playcrossdots-three-verticaleditemptyheartexporteye-with-lineeyefacebookfolderfullheartglobe--smallglobegmailgooglegroupshelp-with-circleimageimagesinstagramFill 1launch-new-window--smalllight-bulblinklocation-pinm-swarmSearchmailmessagesminusmoremuplabelShape 3 + Rectangle 1ShapeoutlookpersonJoin Group on CardStartprice-ribbonprintShapeShapeShapeShapeImported LayersImported LayersImported Layersshieldstartickettrashtriangle-downtriangle-uptwitteruserwarningyahoo

question of taste: properties as lazy evaluators

From: Jms D.
Sent on: Friday, February 24, 2012 4:43 PM
Hello NYCPython -

I have found myself using a property as a lazy evaluation to something that might make a database call. After it is evaluated, the result is cached as `_property_name` on the value and this is used for the rest of the objects lifetime.

In the context of a web framework, appending objects so liberally, according to demand, works well because you have the object itself for a very limited time before it's thrown away and the state is destroyed.

I wrote a blog post about a decorator that essentially does this and I'm wondering if the group has any opinions about using this basic idea. A PyCon friend, whom I link to, told me that the Pyramid project has this technique too, but also offers an improvement.

Yes... I'm linking to my blog. Sorry about that. It's just where the full explanation is.


Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy