On Thu, 26 Jul 2012 18:40:33 -0400 Matt Chaput <matt@whoosh.ca> wrote:
By which I mean a memoryview that lets you change the start and end offsets of its view of the underlying object (not modifying the underlying object).
Let's say I want to slice a long string s into trigrams and write them to disk (or something).
for i in xrange(0, len(s) - 3): x = s[i:i + 3] myfile.write(x)
At each step the slice copies the bytes of the string, even though all I do is write them to disk.
To be honest, copying three bytes is a trivial operation compared to all the rest (interpreting bytecode, instantiating and destructing bytes objects, calling I/O routines, etc.).
Shouldn't I be able to do this?
m = memoryview(s) for i in xrange(0, len(s) - 3): m.start = i m.end = i + 3 myfile.write(m)
You wouldn't win anything over the simple bytes slicing approach, IMO. (even with PyPy or another interpreter) Regards Antoine. -- Software development and contracting: http://pro.pitrou.net