classification
Title: json lib doesnt want to load from file
Type: Stage: resolved
Components: Extension Modules Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Justin Rose, zach.ware
Priority: normal Keywords:

Created on 2019-05-15 22:40 by Justin Rose, last changed 2019-05-15 22:51 by zach.ware. 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) * (Python committer) 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
2019-05-15 22:51:12zach.waresetstatus: open -> closed

type: resource usage ->

nosy: + zach.ware
messages: + msg342613
resolution: not a bug
stage: resolved
2019-05-15 22:40:51Justin Rosecreate