string = "\x22my quote\x22"
print(string)

You don't need to decode, Python 3 does that for you, but you need the correct control character for the double quote "

If however you have a different character set, it appears you have Windows-1252, then you need to decode the byte string from that character set:

str(b"\x94my quote\x94", "windows-1252")

If your string isn't a byte string you have to encode it first, I found the latin-1 encoding to work:

string = "\x94my quote\x94"
str(string.encode("latin-1"), "windows-1252")
Answer from CodeMonkey on Stack Overflow
🌐
Tutorialspoint
tutorialspoint.com › python › string_decode.htm
Python String decode() Method
Welcome to Tutorialspoint.' The decoded string is: Hello! Welcome to Tutorialspoint. The python string decode() method that takes 'utf_32' as its encoding has a variable length encoding done. If the error is specified as 'replace', then it is replaced with a replacement marker.
🌐
Mimo
mimo.org › glossary › python › string-decode
Python string decode(): Syntax, Usage, and Examples
The decode() method in Python is used to convert byte data into a Unicode string. In Python 3, strings are Unicode by default, so decode() applies specifically to bytes objects.
🌐
Reddit
reddit.com › r/learnpython › why was string.decode() removed in python 3?
r/learnpython on Reddit: Why was string.decode() removed in Python 3?
February 23, 2018 -

I'm working on a project where I'm trying to get someone's old Python 2 code updated to work in Python 3, and one of the functions they used was "mystring.decode('hex'). Now I'm trying to figure out how to replicate this functionality in Python 3 and I'm having a hell of a time wrestling with it. Why did Python ditch this?

🌐
GeeksforGeeks
geeksforgeeks.org › python-strings-decode-method
Python Strings decode() method - GeeksforGeeks
April 5, 2025 - In Python 3, the decode method is used to convert a bytes object into a str (string) object by decoding it from a specific encoding.
🌐
Python documentation
docs.python.org › 3 › howto › unicode.html
Unicode HOWTO — Python 3.14.7 documentation
The errors argument specifies the response when the input string can’t be converted according to the encoding’s rules. Legal values for this argument are 'strict' (raise a UnicodeDecodeError exception), 'replace' (use U+FFFD, REPLACEMENT CHARACTER), 'ignore' (just leave the character out of the Unicode result), or 'backslashreplace' (inserts a \xNN escape sequence). The following examples show the differences: >>> b'\x80abc'.decode("utf-8", "strict") Traceback (most recent call last): ...
🌐
Python Central
pythoncentral.io › encoding-and-decoding-strings-in-python-3-x
Encoding and Decoding Strings (in Python 3.x) | Python Central
December 29, 2021 - Encoding and decoding strings in Python 2.x was somewhat of a chore, as you might have read in another article. Thankfully, turning 8-bit strings into unicode strings and vice-versa, and all the methods in between the two is forgotten in Python 3.x.
Find elsewhere
Top answer
1 of 2
4

This is called "unicode-escape" encoding. Here is an example of how one would achieve this behavior in python3:

In [11]: c = b'\xe5\xb8\x90\xe6\x88\xb7'

In [12]: d = c.decode('utf8')

In [13]: print(d)
帐户

In [14]: print(d.encode('unicode-escape').decode('ascii'))
\u5e10\u6237

If you want it as bytes and not str, you can simply get rid of the .decode('ascii').

2 of 2
1

Returning the same unicode as in python2 is not possible : I have not seen unicode object like there was in python2, in python3. But it is possible to get the value of the unicode object.

To do this, you need to do several things :
- Create a byte element with value '\xe5\xb8\x90\xe6\x88\xb7' - Transform this byte element into a string - Gets the unicode code from the string

The first step is quite easy. To create a byte element 'c' with the same value as your c, just do :

c = b'\xe5\xb8\x90\xe6\x88\xb7'

Then, to read the element

c_string = c.decode() # default encoding is utf-8

Finally, I created a function to transform a string into its character + unicode representation

def get_unicode_code(text):
    result = ""
    for char in text:
        ord_value = ord(char)
        if ord_value < 128:
            result += char
        else:
            hex_string = format(ord_value, "x") # turning the int into its hex value
            if len(hex_string) == 2:
                unicode_code = "\\x"+hex_string
            elif len(hex_string) == 3:
                unicode_code = "\\u0"+hex_string
            else:
                unicode_code = "\\u"+hex_string
            result += unicode_code
    return result

get_unicode_code(d) will return the same as d.encode('unicode-escape').decode('ascii'), though it is most likely less efficient.

It takes a string as an argument and returns a string with the unicode instead of the character it represents.

🌐
Linux Hint
linuxhint.com › python-string-decode-method
Linux Hint – Linux Hint
April 10, 2023 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Python Reference
python-reference.readthedocs.io › en › latest › docs › str › decode.html
decode — Python Reference (The Right Way) 0.1 documentation
Defaults to the default string encoding. See codecs module for a full list. ... Optional. errors may be given to set a different error handling scheme. ... Raise ValueError (or a subclass); this is the default. ... Ignore the character and continue with the next. ... Other possible values are any other name registered via codecs.register_error(), see section Codec Base Classes. ... >>> 'źdźbło'.decode('windows-1250') # polish word meaning a blade of grass u'\u0139\u015fd\u0139\u015fb\u0139\u201ao' >>> 'źdźbło'.decode('ascii', 'strict') Traceback (most recent call last): File "<interactive input>", line 1, in <module> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc5 in position 0: ordinal not in range(128) >>> 'źdźbło'.decode('ascii', 'ignore') u'dbo' >>> 'źdźbło'.decode('ascii', 'replace') u'\ufffd\ufffdd\ufffd\ufffdb\ufffd\ufffdo'
🌐
CodeRivers
coderivers.org › blog › decode-python-string
Decoding Python Strings: A Comprehensive Guide - CodeRivers
February 22, 2026 - # Creating a byte string in Python 3 byte_string = b'Hello, World!' decoded_string = byte_string.decode('utf-8') print(decoded_string)
🌐
CodeRivers
coderivers.org › blog › python-decode-string
Python Decode String: A Comprehensive Guide - CodeRivers
February 22, 2026 - byte_string = b'\x48\x65\x6c\x6c\x6f' decoded_string = str(byte_string, 'ascii') print(decoded_string) When reading data from a file, it is important to specify the correct encoding. By default, Python 3's open() function uses the system's default encoding, which may lead to encoding issues.
🌐
Readthedocs
portingguide.readthedocs.io › en › latest › strings.html
Strings — Conservative Python 3 Porting Guide 1.0 documentation
Native strings are suitable mostly for conservative projects, where ensuring stability under Python 2 justifies extra porting effort. It is possible to encode() text to binary data, or decode() bytes into a text string, using a particular encoding.
🌐
DigitalOcean
digitalocean.com › community › tutorials › python-string-encode-decode
Python String Encode and Decode: Complete Guide | DigitalOcean
Master Python string encode() and decode() methods. Learn UTF-8, ASCII, Unicode handling, error handling modes, and practical encoding/decoding examples.
🌐
Python Forum
python-forum.io › thread-10756.html
how to decode UTF-8 in python 3
June 5, 2018 - Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:57:36) on win32 Type "help", "copyright", "credits" or "license" for more information. >>> Str.decode(encoding = 'UTF-8',errors = 'strict') Traceback (most
🌐
Python Module of the Week
pymotw.com › 3 › codecs
codecs — String Encoding and Decoding — PyMOTW 3
December 28, 2016 - $ python3 codecs_decode.py Original : 'français' Encoded : b'66 72 61 6e c3 a7 61 69 73' <class 'bytes'> Decoded : 'français' <class 'str'> ... The default encoding is set during the interpreter start-up process, when site is loaded. Refer to the Unicode Defaults section from the discussion of sys for a description of the default encoding settings. Encoding and decoding strings is especially important when dealing with I/O operations.
🌐
Python Module of the Week
pymotw.com › 2 › codecs
codecs – String encoding and decoding - Python Module of the Week
$ python codecs_encodings.py Raw : u'pi: \u03c0' UTF-8 : 70 69 3a 20 cf 80 UTF-16: fffe 7000 6900 3a00 2000 c003 · Given a sequence of encoded bytes as a str instance, the decode() method translates them to code points and returns the sequence as a unicode instance.
🌐
Medium
medium.com › @vivekmcm1 › understanding-pythons-encode-and-decode-with-real-world-examples-5d2080d66f01
Understanding Python’s encode() and decode() with Real-World Examples | by Vivek | Medium
August 30, 2025 - But have you ever wondered how Python deals with text behind the scenes, especially when sending data over a network, working with files, or communicating with APIs? The answer lies in encode() and decode() functions. ... Encoding is the process of converting a string into bytes.