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

Tim Peters tim at zope.com
Wed Dec 18 15:29:03 EST 2002


[Jeff Kowalczyk]
> I have a class instance attribute which is a string representation of a
> hex value. I need to get the chr() character back.

>>> ashex = '2a'
>>> chr(eval('0x' + ashex))
'*'
>>> chr(int(ashex, 16))
'*'
>>> import binascii
>>> binascii.unhexlify(ashex)
'*'
>>>




More information about the Python-list mailing list