Numeric slicing, iteration prob.
oren-py-l at hishome.net
Wed Aug 7 06:33:31 CEST 2002
On Mon, Aug 05, 2002 at 01:48:45PM +0100, Duncan Smith wrote:
> Does anyone know of a cuter way of iterating over an index rather
> than building strings and using eval()? (Example below.) This will get more
> awkward when I need to do further slicing. eg. depending on the results
> returned I might need to generate t[1,:,3], t[:,1,3] etc.
>>> class Explain:
... def __getitem__(self, index): return index
(1, slice(None, None, None), 3)
(slice(None, None, None), 1, 3)
No need to eval() - generate the equivalent tuple and use it as index.
More information about the Python-list