I have some text encoded to bytes using utf-8 encoding. When processing this text I incautiously used str() to make it a Unicode string because I assumed this would automatically decode the bytes object with the right encoding. This, however, is not the case. For example:
a = "عجائب"
a_bytes = a.encode(encoding="utf-8")
b = str(a_bytes)
yields
b = "b'\\xd8\\xb9\\xd8\\xac\\xd8\\xa7\\xd8\\xa6\\xd8\\xa8'"
which is not what I expected. According to the docs
If neither encoding nor errors is given, str(object) returns
type(object).__str__(object), [...].
So my question is: What is the implemented string representation of a bytes object in Python and can I recreate my original Unicode string from it in general?