lets say i have a string,
"Hello–World"
how would I convert it to something like this
"Hello\u2013World"
where "\u2013"
is the unicode representative of "–"
lets say i have a string,
"Hello–World"
how would I convert it to something like this
"Hello\u2013World"
where "\u2013"
is the unicode representative of "–"
Use str.encode
with unicode_escape
:
>>> print(s.encode('unicode_escape'))
b'Hello\\u2013World'
If you want a string (and to a byte string like above):
>>> print(s.encode('unicode_escape').decode())
Hello\u2013World