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

yaipa h. yaipa at yahoo.com
Thu Jan 2 20:24:14 CET 2003

Well with that said, no one covered using the 'print' method of
base conversion.  Which works well, but looks very Perlish. ;^)

Converting between decimal(string|char|int) to String(dec|hex|oct),
binary and binary(dec|hex) should be part of the core language
as a unified model and not bits and pieces of various modules.  
The way it stands right now, everything works so well in Python
and then you come upon having to move between various types of 
bin/dec/oct/hex and boom, the language just turns kludgy. 
Whoops did I say that. ;-)

There is a lot of hardware code out there written in some version
of BASIC that would really enjoy an obvious way to convert a standard
python type to the equivalent BASIC format seen here 

    (STX$ = CHR$(&H2)).

After many tries, being a die-hard python fan, I settled in using
the print method to do the conversion. Using the print method this
way would be a syntax error in MOST any other language, so it is NOT
obvious by any measure.  Someone new to the language would have 
said, 'screw it' and gone home.

Cameron, BTW you are amazing. How many comp.lang.* groups are you
active on?

Regards of the best kind and thanks for keeping us all honest. Truly.

Alan Haffner

claird at lairds.com (Cameron Laird) wrote in message news:<v01u3f2vc84k80 at corp.supernews.com>...
> 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.

More information about the Python-list mailing list