Robert Rawlins wrote:

I’ve got what seems to me to be a totally illogical math issue here which I can’t figure out. Take a look at the following code:

/self/.__logger.info(/"%i / %i"/ % (bytes_transferred, /self/.__sessions[path].total_bytes))

percentage = bytes_transferred / /self/.__sessions[path].total_bytes * 100

        /self/.__logger.info(/"%i"/ % percentage)

Seems fairly straight forward, you would think. It takes two values and calculates the percentage of one from the other, however, percentage always comes back as ‘0’ for some reason, look at this log output.

if you divide two integers, you'll get an integer back (in Python 2.X, at least). quick fix:

     percentage = bytes_transferred * 100 / total_bytes

</F>

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to