将包含多个列表的文件从读取到python中

将包含多个列表的文件从读取到python中,python,import,Python,Import,这个问题与非常类似,只是我的文件有多行列表,例如 [[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 encodi

这个问题与非常类似,只是我的文件有多行列表,例如

[[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'
我做错了什么?

应该是

第一个函数需要一个文件对象,第二个函数需要一个字符串

希望这有帮助:-)

导入json
打开('idem_perms.txt','r')作为文件:
result=[json.loads(line)表示文件.readlines()中的行]
打印(结果)
产出:

[[[1, 2, 3], [4, 5]], [[1], [4], [6], [1, 2, 3]], [[]], [[1, 5]]]