[issue7028] hex function should work with floats

Josh Cogliati report at bugs.python.org
Thu Oct 1 14:29:21 CEST 2009


Josh Cogliati <jjcogliati-r1 at yahoo.com> added the comment:

Thank you for telling me about that function.  I read the documentation
on hex() and never realized that there was a second instance method
float.hex().  

I am curious why the proper way to turn a number into hex is the following:
import types

def to_hex(a):
    if type(a) == type(0.0):
        return a.hex()
    elif type(a) == type(1):
        return hex(a)
    else:
        raise TypeError('Must be int or float')



As in why does neither int.hex() or hex(float) work?

Thank you.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue7028>
_______________________________________


More information about the Python-bugs-list mailing list