0

I was looking at https://r12a.github.io/app-conversion/ and I see that they have a "JS/Java/C" section. I was wondering if anyone had the code for that in python. I can't seem to find it. Thanks!

Edit: code

b = ''
txt = b.encode('utf-8')
oofer
  • 27
  • 4

1 Answers1

2

From How to work with surrogate pairs in Python? (linked from duplicate Escaped Unicode to Emoji in Python )

If you see '\ud83d\ude4f' Python string (2 characters) then there is a bug upstream. Normally, you shouldn't get such string. If you get one and you can't fix upstream that generates it; you could fix it using surrogatepass error handler:

>>> "\uD83D\uDE00".encode('utf-16', 'surrogatepass').decode('utf-16')
''

Original Answer

Perhaps you're looking for ord()?

Given a string representing one Unicode character, return an integer representing the Unicode code point of that character. For example, ord('a') returns the integer 97 and ord('€') (Euro sign) returns 8364. This is the inverse of chr().

>>> hex(ord(""))
'0x1f600'
ti7
  • 16,375
  • 6
  • 40
  • 68