Python 3.5.2 & json on win 10 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Python 3.5.2 & json on win 10 (/thread-1026.html) Pages:
1
2
|
Python 3.5.2 & json on win 10 - PickyBiker - Nov-28-2016 I have uninstalled python on my win 10 system and re-installed python 3.5.2. The following tiny bit of code causes a series of error messages import json with open('schedule.json') as data_file: data = json.load(data_file) print(data) close("schedule.json")here is the error message: And finally, here is the schedule.json file:{"zones": [[1, 3], [3, 5], [5, 89]], "weekdays": [1, 2], "ontime": [5, 1]} RE: Python 3.5.2 & json on win 10 - micseydel - Nov-28-2016 How are you running your code? I can't reproduce the problem. That said, your last line can be safely removed; the file is closed with the with block automatically. RE: Python 3.5.2 & json on win 10 - PickyBiker - Nov-28-2016 (Nov-28-2016, 12:04 AM)micseydel Wrote: How are you running your code? I can't reproduce the problem. That said, your last line can be safely removed; the file is closed with the with block automatically. I am running from geany. I just tried running it from a command prompt withy python read_json.py and got the same result Are you getting an output? RE: Python 3.5.2 & json on win 10 - micseydel - Nov-28-2016 Here's a terminal session for me on Linux $ cat schedule.json {"zones": [[1, 3], [3, 5], [5, 89]], "weekdays": [1, 2], "ontime": [5, 1]} $ cat testit.py import json with open('schedule.json') as data_file: data = json.load(data_file) print(data) $ python testit.py {u'zones': [[1, 3], [3, 5], [5, 89]], u'weekdays': [1, 2], u'ontime': [5, 1]} $ python3 testit.py {'ontime': [5, 1], 'weekdays': [1, 2], 'zones': [[1, 3], [3, 5], [5, 89]]} RE: Python 3.5.2 & json on win 10 - PickyBiker - Nov-28-2016 Are you running Win 10 and python 3.5.2? RE: Python 3.5.2 & json on win 10 - micseydel - Nov-28-2016 No, I'm using Linux, and I tried Python 2 and Python 3.4. Python and JSON should both be platform independent though, so I don't think that's the problem. My best guess at this point is that you actually have an empty file, and you have an editor window open with unsaved changes. If that's not the case, try running the code import json with open('schedule.json') as data_file: print("<>".format(data_file.read())) # print out the contents of the file, within <> data_file.seek(0) # restore file state so that the below line might work data = json.load(data_file) print(data)You can also try creating a Git repo or something that we can clone and know is reproducing the problem for you, since describing it over the forum might not be enough in this case. RE: Python 3.5.2 & json on win 10 - PickyBiker - Nov-28-2016 I get a different error running the code you provided. Here is the error message I got an a Debian Linux system: I'm afraid I don't understand what "Git repo or something that we can clone" is???
RE: Python 3.5.2 & json on win 10 - micseydel - Nov-28-2016 It looks like you didn't include the import statement. that said, the "<>" line does indicate that the problem is that the .json file is empty. (Nov-28-2016, 04:16 AM)PickyBiker Wrote: I'm afraid I don't understand what "Git repo or something that we can clone" is???Basically a nerdier version of zip files. I'm quite confident at this point that the issue is an empty JSON file, but if you're still having issues, create a zip file with everything needed to reproduce the problem and we can try to use that. RE: Python 3.5.2 & json on win 10 - snippsat - Nov-28-2016 I have testet with win-10 Python 3.5.2 no problem. In most cases your:
paste date in Json Formatter --> Process, now download file and try with this file. RE: Python 3.5.2 & json on win 10 - PickyBiker - Nov-28-2016 Okay, here is the latest status The schedule.json file is okay according to the online json formatter. The simpler code now is: import json with open('schedule.json') as data_file: data = json.load(data_file) print(data)The code and json file work just fine on a debian system. And it still fails with Win 10 system It looks to me that this problem is unique to win 10.
|