Closed Anduie closed 4 years ago
Hi, it looks like something is wrong with your file. Possibly not loading with r so overwriting it or something. But try changing this line:
return json.load(fin)
with this:
text = fin.read()
print("The text is:")
print(text)
return json.loads(text)
To see that you have a valid json file (starting with {
and so on).
That works. I think what happened was I ran part of the code without creating a null dictionary first. So, the JSON was existing as an empty file.
Glad to hear that fixed it!
I have been having issues following along with getting errors that seemed inconsistent with what I thought I should be getting. So, I copied your source for Chapter 9 (linky) and I got the following errors:
Traceback (most recent call last): File "(you don't need to see my roots)/RPS1.py", line 181, in
main()
File "(you don't need to see my roots)/RPS1.py", line 14, in main
show_leaderboard()
File "(you don't need to see my roots)/RPS1.py", line 31, in show_leaderboard
leaders = load_leaders()
File "(you don't need to see my roots)/RPS1.py", line 152, in load_leaders
return json.load(fin)
File "(you don't need to see my roots)\Programs\Python\Python38-32\lib\json__init.py", line 293, in load
return loads(fp.read(),
File "(you don't need to see my roots)Programs\Python\Python38-32\lib\json\init__.py", line 357, in loads
return _default_decoder.decode(s)
File "(you don't need to see my roots)\Programs\Python\Python38-32\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "(you don't need to see my roots)\Programs\Python\Python38-32\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
Process finished with exit code 1
I'm getting the same errors when I'm working on my own sheet along with you and I'm on the Demo: Saving Wins lecture.
So, if I'm reading this correctly, the JSON library is not consistent with what you are wanting it to do. How would I update this library?