You can use unicode_escape
:
>>> thai_string.encode('unicode_escape')
b'\\u0e2a\\u0e35\\u0e40'
Note that encode()
will always return a byte string (bytes) and the unicode_escape
encoding is intended to:
Produce a string that is suitable as Unicode literal in Python source code
More Related Contents:
- What is the best way to remove accents (normalize) in a Python unicode string?
- UnicodeDecodeError: ‘charmap’ codec can’t decode byte X in position Y: character maps to
- How to set sys.stdout encoding in Python 3?
- “Unicode Error “unicodeescape” codec can’t decode bytes… Cannot open text files in Python 3 [duplicate]
- How can I convert surrogate pairs to normal string in Python?
- How to correct TypeError: Unicode-objects must be encoded before hashing?
- Normalizing Unicode
- Facebook JSON badly encoded
- NameError: global name ‘unicode’ is not defined – in Python 3
- Why doesn’t Python recognize my utf-8 encoded source file?
- Python 3 print() function with Farsi/Arabic characters [duplicate]
- How to make unicode string with python3
- Python 3: How to specify stdin encoding
- Identifier normalization: Why is the micro sign converted into the Greek letter mu?
- requests.get returns 403 while the same url works in browser
- What is internal representation of string in Python 3.x
- Set encoding in Python 3 CGI scripts
- How to deal with unicode string in URL in python3?
- Python 3 chokes on CP-1252/ANSI reading
- How to make print() output UTF-8 in Python 3.0?
- UnicodeEncodeError: ‘ascii’ codec can’t encode character u’\xa0′ in position 20: ordinal not in range(128)
- Saving utf-8 texts with json.dumps as UTF8, not as \u escape sequence
- Pinging servers in Python
- Python str vs unicode types
- Directing print output to a .txt file
- Iterate over individual bytes in Python 3
- What is a clean way to convert a string percent to a float?
- discord.py how to wait for author message using wait_for?
- enumerate() for dictionary in Python
- What are assignment expressions (using the “walrus” or “:=” operator)? Why was this syntax added?