On Thu, Aug 28, 2003 at 12:21:47PM +1200, Michael JasonSmith wrote:
> On Thu, 2003-08-28 at 11:43, Nick Rout wrote:
> > z is a one byte hex value. If I print z I get some weird character from
> > the top end of the ascii table, which is expected. However I'd rather
> > have the hex or decimal value,
> > 
> > how do I do this? something to do with a % sign and an x, but I cannot
> > grok it at all.

> >>> f = 0xF7

But look:
>>> type(x)
<type 'int'>

> >>> print '%c' % f
> ?
> >>> print '%d' % f
> 247
> >>> print '%x' % f
> f7

If I understand Nick correctly, the situation is as follows:

>>> z = "\xf7"

And see that:
>>> type(z)
<type 'string'>
>>> print z
�
>>> print "%c" % z
�
>>> print "%d" % z
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: an integer is required
>>> print "%x" % z
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: an integer is required
>>> print "%d" % ord(z)
247
>>> print "%c" % ord(z)
�
>>> print "%x" % ord(z)
f7

Cheers,
-mjg
-- 
Matthew Gregan                     |/
                                  /|                [EMAIL PROTECTED]

Reply via email to