[Tutor] is this use or abuse of __getitem__ ?
eryksun
eryksun at gmail.com
Sat Sep 15 14:37:28 CEST 2012
On Sat, Sep 15, 2012 at 4:43 AM, eryksun <eryksun at gmail.com> wrote:
> else:
> start = index(self.nCases + key if key < 0 else key) # may
> raise TypeError
> stop = start + 1
> step = 1
Gmail is such a pain sometimes. I should have called index first anyway:
key = index(key) # may raise TypeError
start = key + self.nCases if key < 0 else key
stop = start + 1
step = 1
> records = []
> for i in range(start, stop, step):
> ...
> records.append(record)
You can boost the performance here a bit by caching the append method.
This avoids a LOAD_ATTR operation on each iteration:
records = []
append = records.append
for i in range(start, stop, step):
...
append(record)
More information about the Tutor
mailing list