how to get character hex number?

Tim Chase python.list at tim.thechases.com
Fri Aug 31 22:42:57 EDT 2012


On 08/31/12 21:21, contro opinion wrote:
>>>> for i in "english" :
> ...   print(hex((ord(i))))
> ...
> 0x65
> 0x6e
> 0x67
> 0x6c
> 0x69
> 0x73
> 0x68
>>>> u"english".encode("utf-8")
> 'english'
>>>> u"english".encode("ascii")
> 'english'
> 
> how can i get 656e676c697368 in encode method?

At least in 2.x, you can do:

>>> u"english".encode("hex")
'656e676c697368'

-tkc






More information about the Python-list mailing list