how to get character hex number?

Ian Kelly ian.g.kelly at gmail.com
Fri Aug 31 22:40:32 EDT 2012


On Fri, Aug 31, 2012 at 8:21 PM, contro opinion <contropinion at gmail.com> 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?

>>> ''.join("%02x" % ord(b) for b in u"english".encode("ascii"))
'656e676c697368'



More information about the Python-list mailing list