The usual way we create a bytes variable in python is use the following way:
b = b'some text i do not care'
For example, the chinese character string "鲁邦三世" encode to bytes type is :
str_ch = "鲁邦三世"
encoded_str_ch = str_ch.encode("utf-8")
print(encoded_str_ch) # b'\xe9\xb2\x81\xe9\x82\xa6\xe4\xb8\x89\xe4\xb8\x96'
now if i have a string:
s = '\xe9\xb2\x81\xe9\x82\xa6\xe4\xb8\x89\xe4\xb8\x96'
# same with encoded_str_ch, but it's string type
how can i initialize a bytes variable just use the variable s, not the encoded string '\xe9...\x96'
i tried
bytes(str_ch, encoding = "utf8")
but it's not correct, still got the same result with s
or there is not a way to do this...