Jump to content
Che

Cum obtin acest cod in Python ?

Recommended Posts

Posted

Am U+1F498 care este un code unicode.

Facand asa:

print "&#" + str(int("0001F498", 16))

Imi arata asta: &#128152 

Care cica ar fi "HTML Entity (decimal): 💕" conform acestui site: https://www.fileformat.info/info/unicode/char/1f495/index.htm

 

Stie cineva cum as putea sa fac sa imi arate 55,357 in loc de acest 128152 de mai sus ?

Tot dupa situl de mai sus se pare ca ar fi un UTF-16, dar cum il pot obtine in python plecand de la unicode pointul de mai sus ?

Multumesc mult de tot!

  • Upvote 1
Posted
import codecs
emoji=u"\U0001F498"
encoded=emoji.encode('utf-16be')
t=codecs.encode(encoded,'hex_codec')
tt=codecs.decode(t,'ascii')
prim=tt[0:4]
secund=tt[4:]
print("Primul numar:",int(prim,16), "Al doilea:",int(secund,16))

 

  • Thanks 1
  • Upvote 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...