Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
类型错误:';dict';对象不可调用-尝试向python列表中添加其他属性时_Python_Python 3.x_Python Requests_Append - Fatal编程技术网

类型错误:';dict';对象不可调用-尝试向python列表中添加其他属性时

类型错误:';dict';对象不可调用-尝试向python列表中添加其他属性时,python,python-3.x,python-requests,append,Python,Python 3.x,Python Requests,Append,我正试图将带有两个json返回值的python列表附加到我的最终列表中 我的代码: data = json.loads(r.text) final_list = [] for each_req in data: final_list.append(each_req(['requestId'],['author'])) return final_list 错误: TypeError:“dict”对象不可调用 如果我尝试相同的方法,但仅使用reque

我正试图将带有两个json返回值的python列表附加到我的
最终列表中

我的代码:

    data = json.loads(r.text)
    final_list = []
    for each_req in data:
        final_list.append(each_req(['requestId'],['author']))
    return final_list
错误:

TypeError:“dict”对象不可调用

如果我尝试相同的方法,但仅使用
requestId
即可:

    data = json.loads(r.text)
    final_list = []
    for each_req in data:
        final_list.append(each_req['requestId'])
    return final_list
然后列表中包含“12345”等值

如何将最终列表附加为如下所示:

“12345无名氏”

做一些类似于:

tup=(每个请求['requestId'],每个请求['author'])
最终列表追加(tup)
each_req()
表示它是一个函数和/或以某种方式可调用,但实际上不是,因此出现错误请尝试:

final_list.append(each_req['requestId'], each_req['author'])

您需要再次访问字典才能将值附加到列表中

试试这个:

final_list.append(each_req['requestId'] + each_req['author'])

假设您的 数据类似于data={'key1':{'requestId':12345,'author':'Myname'} 因为'data'中的i返回字典中的'keys',而i['key1']不会返回值 那把钥匙的钥匙

然后试试这个代码

def foo():
    data = {'key1':{'requestId':12345,'author':'Myname'}}
    final_list = []
    for each_req in data:
        final_list.append(f"{data[each_req]['requestId']} {data[each_req]['author']}")
    return final_list

print(foo())