[Python] Converting unicode string to hexadecimal representation

Discussão em 'Python' iniciado por Stack, Setembro 25, 2024.

  1. Stack

    Stack Membro Participativo

    I want to convert unicode string to its hexadecimal representation. For example, u'\u041a\u0418\u0421\u0410' should be converted to "\xD0\x9A\xD0\x98\xD0\xA1\xD0\x90". I tried the code below (python 2.7):

    unicode_username.encode("utf-8").encode("hex")


    However, I get a string:

    'd09ad098d0a1d090'


    Any suggestions how I can get \xD0\x9A\xD0\x98\xD0\xA1\xD0\x90?

    Continue reading...

Compartilhe esta Página