D. Hartley wrote: > I have a question: what is the "opposite" of hex()? (i.e., like ord > and chr). If I have > > '0x73', how can I get back to 115 or s?
I don't know a really clean way to do this because '0x73' is not a legal input value for int(). The simplest way is to use eval(): >>> eval('0x73') 115 but eval() is a security hole so if you are not 100% sure of where your data is coming from then this is probably a better solution (it strips off the '0x' then tells int() to convert base 16): >>> int('0x73'[2:], 16) 115 To go from the string '115' to the integer 115 you can use int() directly: >>> int('115') 115 To get back to a string use chr(): >>> chr(115) 's' All of these functions are documented here: http://docs.python.org/lib/built-in-funcs.html Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor