[Tutor] is this use or abuse of __getitem__ ?
eryksun at gmail.com
Mon Sep 17 12:18:13 CEST 2012
On Mon, Sep 17, 2012 at 3:42 AM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
> Another idea would be to also use __getitem__ as a dictionary. So when
> the data contains an id (let's say ssn), r = Reader(key="ssn");
> r.data["87654321"] returns the corresponding (first available) record.
> But although this is cool from an educational perspective, I do wonder
> whether, from a design perspective, it's a good idea to make __getitem__
> this fully packed.
Maybe have a mappingview() method that returns a lazy mapping view of
the object. That way you're not mixing up indexed and mapping
More information about the Tutor