Equivalent to chr(eval(self.myhex)) without using eval?

Christos TZOTZIOY Georgiou DLNXPEGFQVEB at spammotel.com
Wed Jan 1 16:04:31 EST 2003


On Wed, 18 Dec 2002 15:06:20 -0500, rumours say that "Jeff Kowalczyk"
<jtk at yahoo.com> might have written:

>>>> class Foo:
>...  def __init__(self):
>...   self.myhex = '0x2a'
>...  def bar(self):
>...   print chr(eval(self.myhex))

If the representation contains the '0x' prefix, you can do it as:
print chr(int(self.myhex, 0))

If it's without it, you can
print self.myhex.decode('hex')

Don't know if the latter is available for Zope currently :(
-- 
TZOTZIOY, I speak England very best,
Real email address: 'dHpvdEBzaWwtdGVjLmdy\n'.decode('base64')




More information about the Python-list mailing list