1

Possible Duplicate:
how to parse hex or decimal int in Python

i have a bunch of Hexadecimal colors in a database stored as strings.

e.g. '0xFFFF00'

when i get them from the database i need to convert this string into an actual hexadecimal number, so

0xFFFF00

how can i do this in python

Community
  • 1
  • 1
JiminyCricket
  • 7,050
  • 7
  • 42
  • 59

3 Answers3

5

This is one way to do it:

>>> s = '0xFFFF00'
>>> i = int(s, 16)
>>> print i
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
0

hex(int('0xFFFF00', 16))

leoluk
  • 12,561
  • 6
  • 44
  • 51
0

Also this works

number = int('0xFFFF00',0)
print("%x follows %x" % (number+1, number))

0 argument tells interpreter to follow the Python rules of numbers to decide the used format of number so this expression will work right for all numbers.

Tony Veijalainen
  • 5,447
  • 23
  • 31