Closed randyheydon closed 9 years ago
Thank you, after fixing divisions, Ive checked with python2 -Q warnall bcam-launcher , it only shows GTK-related issues now, also hand-tested bcam, it works, but definetely bcam needs better way for auto testing.
By default in Python 2, division behaves differently based on the types of the two operands.
1/2
(integer divided by integer) results in floor division, so the result is0
. However,1.0/2
uses true division, giving a result of0.5
.As of Python 2.2 (through PEP 238), it has been possible to explcitly choose which division type to use. Floor division can be forced with the
//
operator (so1.0//2.0 == 0.0
), and all other division can be switched to true division by addingfrom __future__ import division
to the top of the file (so1/2 == 0.5
). In Python 3, true division is the default behaviour.I am trying to change BCAM to use division explicitly, but to do that I need to know what form of division is intended each time its used. I grepped for
/
to find all instances of division. Some of them are obvious as they include things likex/2.0
, but others are not. Runningpython2 -Q warnall bcam-launcher
will print warnings every time division is used, showing which type is used where. However, I found that several lines in main.py would do both, sometimes doing floor division and sometimes doing true division. Furthermore, there were a number of division operations that I wasn't able to trigger, as I don't know enough about the code to reach them.In conclusion, please replace all intended floor divisions with the
//
operator, then add thedivision
future import to each file. This will make the code more explicit in its intent, and is another step toward Python 3 compatibility.