Quickie: converting r"\x2019" to int

Robin Haswell rob at digital-crocus.com
Fri Apr 7 04:42:50 EDT 2006


On Thu, 06 Apr 2006 20:00:13 +0200, Just wrote:

> In article <4435501d$1_2 at newspeer2.tds.net>,
>  Kent Johnson <kent at kentsjohnson.com> wrote:
> 
>> Robin Haswell wrote:

>> Is this what you mean?
>> In [9]: int(r'\x2019'[2:], 16)
>> Out[9]: 8217
>> 
>> or maybe you meant this:
>> In [6]: ord(u'\u2019')
>> Out[6]: 8217
> 
> Or even:
> 
>   >>> import struct 
>   >>> struct.unpack("q", "\0\0"+ r'\x2019')[0]
>   101671307850041L
>   >>> 


rob at aranea:~$ python
Python 2.4.2 (#2, Sep 30 2005, 21:19:01) 
[GCC 4.0.2 20050808 (prerelease) (Ubuntu 4.0.1-4ubuntu8)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> int("\x2019")
19
>>> 

Something like that. Except with:

>>> int(r"\x2019")
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): \x2019
>>> 


:-)

-Rob



More information about the Python-list mailing list