to convert <class 'bytes'> data in tuple in python? example:
data = b'["1","2","3"]'
data = tuple(data)
print(data)
output:(91, 34, 49, 34, 44, 34, 50, 34, 44, 34, 51, 34, 93)
But i need output like below. Expected output:
data = (1,2,3)
One approach is first to decode the byte-string then use ast.literal_eval to convert it to list:
from ast import literal_eval
data = b'["1","2","3"]'
res = literal_eval(data.decode("utf-8"))
res = tuple(res)
print(res)
Output
('1', '2', '3')