kutsurak / python-bitstring

Automatically exported from code.google.com/p/python-bitstring
0 stars 0 forks source link

Stepping in slices should have conventional meaning #108

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
hi,

I would like to get a slice of a ConstBitArray with a step bigger than one, the 
same I would do with a list:

s = mylist[start, stop, step]

is it possible to do that in bitstring?

thanks

Original issue reported on code.google.com by andrea.z...@gmail.com on 18 Apr 2011 at 9:34

GoogleCodeExporter commented 9 years ago
The step does have a function, but not the standard list one - it instead acts 
as a multiplier for the start and stop. This is helpful if you want to specify 
things in terms of bytes or other bit multiples (so s[a:b:c] is the same as 
s[a*c:b*c]).

For the behaviour you seem to want there's not such a compact syntax. I'd be 
interested to know what you need it for (I could never think of a use for it 
which is why the other use for step was chosen). The best equivalent I can 
think of is 

    s = ConstBitArray().join(m[i:i+1] for i in range(start, stop, step))

If all you want to do is check that all or any of the bits are set/unset then 
you can use something like

    m.all(True, range(start, stop, step))

or 

    m.any(False, range(start, stop, step))

Original comment by dr.scott...@gmail.com on 18 Apr 2011 at 10:44

GoogleCodeExporter commented 9 years ago
The standard step functionality would be useful when retrieving a column from a 
2D bit array, and probably in other situations too. The current functionality 
doesn't appear to have caught on, so consider switching to more usual meaning 
in version 3.0.

Original comment by dr.scott...@gmail.com on 18 Jun 2011 at 6:24

GoogleCodeExporter commented 9 years ago
Done for version 3.0.

Original comment by dr.scott...@gmail.com on 20 Nov 2011 at 9:16