Konvertieren Sie die Datei, um zu dikten, wo Wert ein Code ist, z. Povscore (1,2)Python

Python-Programme
Anonymous
 Konvertieren Sie die Datei, um zu dikten, wo Wert ein Code ist, z. Povscore (1,2)

Post by Anonymous »

Ich habe folgende Daten (7 MB) und es ist in Transposion gespeichert.txt: < /p>

Code: Select all

{'0x2df54c975eb48346': [PovScore(Cp(+57), BLACK), 5], ...}
< /code>
Ich habe versucht < /p>
with open("transposition.txt", "r") as file:
x = file.readline()
transposition = eval(x)
del x
< /code>
Aber der Speicher erreicht 99% und hängt dann. Ich habe es mit 1 MB -Datei versucht, sie wird sofort geladen und die Zeichenfolge gesetzt, aber beim Drucken ist sie sehr langsam (Leerlauf): < /p>
>>> with open("testfile.txt", "r") as file:
x = file.read()

>>> x
Squeezed text (2000 lines)
< /code>
json
Modul kann JSON nicht mit Code analysieren:

Code: Select all

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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post