这个问题与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'
我做错什么了?你知道吗
输出:
^{} 应该是^{} 。你知道吗
第一个函数需要一个文件对象,第二个函数需要一个字符串。你知道吗
希望这有帮助:-)
相关问题 更多 >
编程相关推荐