【发布时间】:2020-02-25 22:33:33
【问题描述】:
这个问题和Reading a list of lists from a file as list of lists in python很相似,只是我拥有的文件有多行带有列表的列表,比如
[[1,2,3],[4,5]]
[[1], [4], [6], [1,2,3]]
[[]]
[[1,5]]
按照上述链接的建议,我的以下尝试失败了
import json
f = open('idem_perms.txt', 'r')
for line in f:
e = json.load(line)
抛出错误
--> 287 return loads(fp.read(),
288 encoding=encoding, cls=cls, object_hook=object_hook,
289 parse_float=parse_float, parse_int=parse_int,
AttributeError: 'str' object has no attribute 'read'
我做错了什么?
【问题讨论】: