jon+usenet at unequivocal.co.uk
Mon Oct 27 16:11:48 CET 2014
On 2014-10-26, Tim Delaney <timothy.c.delaney at gmail.com> wrote:
> On 27 October 2014 01:14, Jon Ribbens <jon+usenet at unequivocal.co.uk> wrote:
>> I have a need, in a Python C extension I am writing, for lists and
>> dictionaries with "lazy evaluation" - by which I mean that at least
>> some of the values in the lists/dictionaries are "proxy objects"
>> which, rather than returning as themselves, should return the thing
>> they are a proxy for when retrieved. This is because retrieving
>> the proxied objects is expensive and only a small minority of them
>> will actually be accessed, so retrieving them all before they are
>> actually accessed is massively inefficient.
> Why not put proxy objects into the list/dict?
That's precisely what I am doing. The point is that when they are
retrieved they need to be resolved into the genuine objects.
> Have a look at the weakref module for an API that may be suitable
> for such proxy objects (if you used the same API, that would also
> allow you to transparently use weakrefs in your lists/dicts).
Hmm, the idea behind that appears to be to create a proxy that
emulates every possible method of every conceivable type. My
method of only emulating the list and dict methods seems to be
somewhat simpler for my purpose ;-)
More information about the Python-list