FAQ: How do I calculate what quoted strings and numbers mean?

p.lavarre at ieee.org p.lavarre at ieee.org
Mon Nov 20 22:44:10 CET 2006


> > > int('0x100', 0x10) ...
> >
> > ... evals that apparently don't import os, such as ...
> >
> > int('0x100'[2:], 0x10)
> > float('1.23e+4')
> > binascii.unhexlify('4142')
> >
> > ... for literal string args?
> > http://docs.python.org/ref/strings.html
>
> http://docs.python.org/lib/standard-encodings.html
> a = r'hello\nthere'
> print a.decode('string_escape')

Bingo, thank you:

>>> binascii.hexlify(repr('\xA3')[1:-1].decode('string_escape'))
'a3'
>>> binascii.hexlify(repr(u'\u00A3')[2:-1].decode('unicode_escape').encode('UTF-8'))
'c2a3'
>>>




More information about the Python-list mailing list