I have nothing particularly useful to add, only that this is potentially a
really fantastic idea with a lot of promise, IMO.
It would be nice to have some view objects with a lot of functionality that
can be sliced not only for efficiency, but for other purposes. One might be
(note that below I am assuming that slicing a view returns another view):
nodes = [(0,0), (1,0), (1,1), (1,0)]
triangle1 = [view_of_node_idx0, view_of_node_idx1, view_of_node_idx3]
triangle2 = [view_of_node_idx1, view_of_node_idx2, view_of_node_idx3]
Now if I move the node locations, the triangles reflect the update:
nodes[:] = (1,1), (2,1), (2,2), (2,1)
Even tried implementing something like a simple sequence view myself once,
but got stuck trying to reliably slice slices and couldn't decide what it
should mean to return single values from the view (an atomic "slice"? just
return the value?), and there are probably all kinds of subtleties way
above my knowledge level to consider:
from itertools import islice
class SeqView:
def __init__(self, seq, sl=slice(None)):
self.seq = seq
self.sl = sl
def __repr__(self):
return f"{self.__class__.__name__}({self.seq}, {self.sl})"
def __str__(self):
return f"{self.seq[self.sl]!s}"
def __getitem__(self, key):
if isinstance(key, slice):
return self.__class__(self.seq, <need to calculate a slice of a
slice here>)
# even if just returning the value, surely this could be much
better?
return list(islice(self.seq, self.sl.start, self.sl.stop,
self.sl.step))[key]
---
Ricky.
"I've never met a Kentucky man who wasn't either thinking about going home
or actually going home." - Happy Chandler
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/BRM3ZXEU6W3YUF47PKGDRZTJ6KJNIF3B/
Code of Conduct: http://python.org/psf/codeofconduct/