On 4/2/2010 6:59 PM, kj wrote:
In<xns9d4ec021dc8eaduncanbo...@127.0.0.1> Duncan
Booth<duncan.bo...@invalid.invalid> writes:
class Spam(object):
mongo = None
def __call__(self, x, y, z):
if self.mongo is None:
self.mongo = heavy_lifting_at_runtime()
return frobnicate(x, y, z, self.mongo)
Unless one wants the intialization of mongo delayed in case spam is
never called, it can go in __init__ instead.
spam = Spam()
ham = spam(1, 2, 3)
I really like this. Thanks.
That's natural and readable.
From reading this thread, and the "(a==b) ? 'Yes' : 'No'" one, the
inescapable conclusion is that "readability" (like beauty) is very
much in the eye of the beholder, or, in this case, in the eye of
Guido.
~K
--
http://mail.python.org/mailman/listinfo/python-list