У меня есть следующие данные (7 МБ), которые хранятся в transpostion.txt:
Код: Выделить всё
{'0x2df54c975eb48346': [PovScore(Cp(+57), BLACK), 5], ...}
Код: Выделить всё
with open("transposition.txt", "r") as file:
x = file.readline()
transposition = eval(x)
del x
Код: Выделить всё
>>> with open("testfile.txt", "r") as file:
x = file.read()
>>> x
Squeezed text (2000 lines)
Код: Выделить всё
json
Код: Выделить всё
Traceback (most recent call last):
File "", line 1, in
json.dumps({'a':PovScore(0,0)})
File "C:\Users\asdfs\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Users\asdfs\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\asdfs\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\asdfs\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type PovScore is not JSON serializable
Источник: https://stackoverflow.com/questions/781 ... ovscore1-2