- Joined
- Sep 10, 2013
- Messages
- 7,944
- Helped
- 1,823
- Reputation
- 3,656
- Reaction score
- 1,808
- Trophy points
- 1,393
- Location
- USA
- Activity points
- 60,209
I'm trying to use the cut method from bitstring and have been running into a discrepancy with the behavior called out on the example given under cut shows the following:
Now on my Win7 64-bit system I have both the 2.7.8 and 3.4.1 win32 versions from python.org installed. The problem is both of them produce the following output instead.
0x11111234
Now in some respects it makes more sense, since s is being updated with the prepend method, but according to the example given, it seems that the generator s.cut(4) should be using a local copy of s in the for loop, while it iterates over the 4 nibbles. Instead it appears that the s bit array is being operated on directly, thereby adding a 1 nibble each time (which results in the next for loop iteration cutting the same 1 from s each time).
I've tried searching for more information on the bitstring module, but everything references back to the same pythonhosted.org site. I get the impression that this is a documentation problem, but want to make sure it's not something else like making s global or something (not sure python has globals, I've only just started learning it).
Thanks in advance for any insights into what is going on.
Regards
Code:
>>> s = BitString('0x1234')>>> for nibble in s.cut(4):
... s.prepend(nibble)
>>> print(s)
0x43211234
Now on my Win7 64-bit system I have both the 2.7.8 and 3.4.1 win32 versions from python.org installed. The problem is both of them produce the following output instead.
0x11111234
Now in some respects it makes more sense, since s is being updated with the prepend method, but according to the example given, it seems that the generator s.cut(4) should be using a local copy of s in the for loop, while it iterates over the 4 nibbles. Instead it appears that the s bit array is being operated on directly, thereby adding a 1 nibble each time (which results in the next for loop iteration cutting the same 1 from s each time).
I've tried searching for more information on the bitstring module, but everything references back to the same pythonhosted.org site. I get the impression that this is a documentation problem, but want to make sure it's not something else like making s global or something (not sure python has globals, I've only just started learning it).
Thanks in advance for any insights into what is going on.
Regards