Answers for "convert bytes to dict in python"

0

python bytes to dict

# credit to the Stack Overflow user in the source linnk
# Python3

import ast

byte_str = b"{'one': 1, 'two': 2}"
dict_str = byte_str.decode("UTF-8")
my_data = ast.literal_eval(dict_str)

print(repr(my_data))
>>> {'one': 1, 'two': 2}
Posted by: Guest on June-02-2021
-1

python convert b string to dict

# python3
import ast
byte_str = b"{'one': 1, 'two': 2}"
dict_str = byte_str.decode("UTF-8")
mydata = ast.literal_eval(dict_str)
print(repr(mydata))
Posted by: Guest on November-25-2020

Code answers related to "convert bytes to dict in python"

Python Answers by Framework

Browse Popular Code Answers by Language