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

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

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -