Escaping a string for c code

hi, iā€™m trying to generate c code from python, and currently using json.dumps to make string literals. however it has a problem with high characters:

>>> eval(json.dumps("šŸ§›"))
'\ud83e\udddb'
>>> "šŸ§›"
'šŸ§›'

what is the proper way to do it?

Very much depends on other details of what you are trying to achieve.

Some things that might help you:

u = 'šŸ§›'
b = u.encode('unicode_escape')
u2 = b.decode('unicode_escape')

o = ord(u)
u3 = chr(o)

print(u2)
print(u3)
print(json.loads(json.dumps("šŸ§›")))

:vampire:
:vampire:
:vampire:

thank you, s.encode('unicode_escape') is exactly what i need!