floating point - python float to in int conversion -
i have issue drives me mad. doing int(20.0)
result in 20
. far good. but:
levels = [int(gex_dict[i]) in sorted(gex_dict.keys())]
while gex_dict[i]
returns float, e.g. 20.0
, results in:
"invalid literal int() base 10: '20.0'"
i 1 step away munching last piece of keyboard.
'20.0'
string, not float
; can tell single-quotes in error message. can int
out of first parsing float
, truncating int
:
>>> int(float('20.0')) 20
(though maybe you'd want store floats instead of strings in dictionary, since seem expecting.)
Comments
Post a Comment