title: Converting a hexadecimal character to an int in Python
body: <p>I'm using the graphics library <a href="http://en.wikipedia.org/wiki/Pyglet" rel="nofollow">Pyglet</a> to do some drawing and want to get the resulting image out as a Python list (so I can convert it to a <a href="http://en.wikipedia.org/wiki/NumPy" rel="nofollow">NumPy</a> array).</p>
  
  <p>Pyglet gives me a string of hex characters, like this: '\xff' (indicating a value of 255 at one pixel). How can I convert such a string to an int?</p>
  
  <p>I've tried int('\xff', 16), but that doesn't work. Note that according to <a href="http://docs.python.org/reference/lexical_analysis.html#string-literals" rel="nofollow">the documentation</a>, '\xnn' is escaped and encoded as a hexedecimal char, but it doesn't tell me how to convert that to an int.</p>