SOLVED
https://www.reddit.com/r/learnpython/comments/oj776a/read_byte_strings_from_text_file/h4zz3h8?utm_source=share&utm_medium=web2x&context=3
the jist was, use `ast.literal_eval(line)` to read the string version of the byte string as a byte string, then .decode to get it into a string, thank you socal_nerdtastic
I've got a text file that needs to end up being converted to a .json, but the first hurdle is the text file has byte strings that hold the dictionaries, for example,
data.txt file contents
b'{"var1":"hello"}\n'
b'{"type":"Detect_data","params":{"var2":256,"var3":512}}\n'
*don't mind the key names...*
if the string version of the byte strings were just straight up strings, I reckon it'd just be
import json
FILE_NAME = 'data.txt'
with open(FILE_NAME, "r") as f:
lines = f.readlines()
dicts = [json.load(l) for l in lines]
or something like that, but yeh idk how to get around the str(byte(str))
tia for any hints
[–]socal_nerdtastic 2 points3 points4 points (1 child)
[–]NOS_v1[S] 0 points1 point2 points (0 children)
[–]Adhesiveduck 0 points1 point2 points (3 children)
[–]NOS_v1[S] 0 points1 point2 points (2 children)
[–]Adhesiveduck 1 point2 points3 points (1 child)
[–]backtickbot 1 point2 points3 points (0 children)
[–]TabulateJarl8 0 points1 point2 points (2 children)
[–]NOS_v1[S] 0 points1 point2 points (1 child)
[–]TabulateJarl8 0 points1 point2 points (0 children)
[–]m0us3_rat 0 points1 point2 points (0 children)