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

Cameron Laird claird at lairds.com
Wed Dec 18 17:36:31 EST 2002


In article <mailman.1040243490.26231.python-list at python.org>,
Tim Peters <tim at zope.com> wrote:
>[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)
>'*'
>>>>
>

Python:  the language which offers more than one wizardly way
to do something.
-- 

Cameron Laird <Cameron at Lairds.com>
Business:  http://www.Phaseit.net
Personal:  http://phaseit.net/claird/home.html



More information about the Python-list mailing list