Quickie: converting r"\x2019" to int
Fredrik Lundh
fredrik at pythonware.com
Thu Apr 6 14:07:10 EDT 2006
Just wrote:
> > Robin Haswell wrote:
> > > Hey guys. This should just be a quickie: I can't figure out how to convert
> > > r"\x2019" to an int - could someone give me a hand please?
> >
> > 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
> >>>
>
> Who knows :)
I think we can be pretty sure that he didn't mean
>>> import unicodedata
>>> unicodedata.numeric(u"\u2019")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: not a numeric character
though...
>>> unicodedata.name(u"\u2019")
'RIGHT SINGLE QUOTATION MARK'
</F>
More information about the Python-list
mailing list