Python data unicode conversion -


i have following list:

list = [u'0', u'ff', u'7', u'0', u'ff', u'fff', u'fff'] 

and need use elements integer or float when try convevrting following error:

>>> float(list[1]) traceback (most recent call last):   file "<interactive input>", line 1, in <module> valueerror: not convert string float: ff 

is there way of solving this?

you can not convert hex values float directly, instead can convert int specifying proper base using int() function :

>>> l = [u'0', u'ff', u'7', u'0', u'ff', u'fff', u'fff'] >>> [int(i,16) in l] [0, 255, 7, 0, 255, 4095, 4095] 

or use float on int values :

>>> [float(int(i,16)) in l] [0.0, 255.0, 7.0, 0.0, 255.0, 4095.0, 4095.0] 

Comments

Popular posts from this blog

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -

javascript - Using jquery append to add option values into a select element not working -

javascript - Restarting Supervisor and effect on FlaskSocketIO -