TypeError after 2to3
I have used 2to3 to run this library and I keep on running into a TypeError of:
TypeError: unsupported operand type(s) for >>: 'float' and 'int'
def get_lexographically_next_bit_sequence(self, bits): t = (bits | (bits - 1)) + 1 next = t | ((((t & -t) // (bits & -bits)) >> 1) - 1) yield next while True: t = (next | (next - 1)) + 1 next = t | ((((t & -t) // (next & -next)) >> 1) - 1) yield next
I have tried other parts of the library and they work, so I'm pretty confident that 2to3 worked fine. It's only when I load the evaluator that this message pops up. Any thoughts?
I have the same issue while running go.py.
/ means float division in Python 3. If you want integer division, use /. Unfortunately, 2to3 isn't smart enough to take care of this for you.
There's a PR here that takes care of Py3 compatibility: #21 (apparently duplicated by #23).
@mpenkov thanks but did your answer not format properly? I guess I'm not seeing a difference in the slashes as you mention them. I have tried using both / and // in my code and it will still not work.
@nittanycolonial Whoops. Here's what I meant:
If you want integer division, use //
Have a look at the pull-requests I mentioned for more info.
Hello guys, I did a pull to the original project and I couldn't seem to get it working straight away on python3.5. I've forked the project and it now works with python3.5.
The main things were: 1.) Python 2 does floor division with the / operator, Python 3 introduced // for floor division. 2.) For some reason after having done 2to3 conversion, I was getting a byte object in the section of the code and had to change it to string for it to work.
hope this helps.