Efficient multi-slicing technique?

python at bdurham.com python at bdurham.com
Mon Jan 26 03:16:26 CET 2009


> I'm not sure if it's more efficient, but there's the struct module:
> http://docs.python.org/library/struct.html

Thanks for your suggestion. I've been experimenting with this technique,
but my initial tests don't show any performance improvements over using
slice() objects to slice a string. However, I missed the nuance of using
'x' to mark filler bytes - I'm going to see if this makes a difference
(it may as I am skipping over several columns of input that I've been
currently returning as ignored values)

<reading your link to doc ...> wait ... it looks like I can 'compile'
struct strings using by using a Struct class vs. the using the module's
basic unpack() function. This sounds like the difference between using
compiled regular expressions vs. re-compiling a regular expression on
every use. I'll see if this makes a difference and report back to the


More information about the Python-list mailing list