Issue 36931: json lib doesnt want to load from file
Created on 2019-05-15 22:40 by Justin Rose, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| main.py | Justin Rose, 2019-05-15 22:40 | program file | ||
| Messages (2) | |||
|---|---|---|---|
| msg342609 - (view) | Author: Justin Rose (Justin Rose) * | Date: 2019-05-15 22:40 | |
when I run the included file i get an error that looks like:
Traceback (most recent call last):
File "/home/justin/Desktop/pkmn/main.py", line 10, in <module>
expansion = json.load(expan_list)
File "/usr/lib/python3.6/json/__init__.py", line 296, in load
return loads(fp.read(),
AttributeError: 'str' object has no attribute 'read'
dont know what to make of it
|
|||
| msg342613 - (view) | Author: Zachary Ware (zach.ware) * ![]() |
Date: 2019-05-15 22:51 | |
You're passing in a filename, not a file-like object (see https://docs.python.org/3/library/json.html#json.load). Instead, you'll want something like: with open(filename) as f: json_data = json.load(f) Please note that this is not a help forum; in future, please submit queries like this to the python-list@python.org mailing list, StackOverflow, or if you're just learning Python, try the tutor@python.org mailing list. Thanks! |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:15 | admin | set | github: 81112 |
| 2019-05-15 22:51:12 | zach.ware | set | status: open -> closed type: resource usage -> nosy:
+ zach.ware |
| 2019-05-15 22:40:51 | Justin Rose | create | |
