Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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
Python 使用函数类型错误遍历列表_Python_List_Function - Fatal编程技术网

Python 使用函数类型错误遍历列表

Python 使用函数类型错误遍历列表,python,list,function,Python,List,Function,我对python非常陌生,我一直在udemy上学习,只是在业余时间玩。我正在使用一些生成dict/list的函数。我遇到“TypeError:“list”对象不可调用”问题 所以保存文本文件是可行的。如果我删除bot-in-botlist循环并手动设置id,它将正确创建文本文件。当我尝试在for循环中运行它时,我得到了类型错误。但它确实列出了打印函数中的机器人id,然后创建了第一组文本文件。print函数int results是我需要输入deala和dealsf函数的botid的正确整数。我猜我

我对python非常陌生,我一直在udemy上学习,只是在业余时间玩。我正在使用一些生成dict/list的函数。我遇到“TypeError:“list”对象不可调用”问题

所以保存文本文件是可行的。如果我删除bot-in-botlist循环并手动设置id,它将正确创建文本文件。当我尝试在for循环中运行它时,我得到了类型错误。但它确实列出了打印函数中的机器人id,然后创建了第一组文本文件。print函数int results是我需要输入deala和dealsf函数的botid的正确整数。我猜我做的迭代是错误的,但不知道如何纠正它。以下是电流输出:

2649989
<class 'int'>
2642117
<class 'int'>
2628896
<class 'int'>
2555868
<class 'int'>
2536597
<class 'int'>
2481665
<class 'int'>
2392904
<class 'int'>
2367291
<class 'int'>
Traceback (most recent call last):
  File "path", line 79, in <module>
    error, dealsa = dealsa(botid)
TypeError: 'list' object is not callable
2649989
2642117
2628896
2555868
2536597
2481665
2392904
2367291
回溯(最近一次呼叫最后一次):
文件“路径”,第79行,在
错误,dealsa=dealsa(botid)
TypeError:“列表”对象不可调用

我真的很困惑为什么第一个打印for loop可以工作,但是第二个打印会抛出类型错误。

您的问题发生在这一行:

error, dealsa = dealsa(botid)
在这里,您将用调用它的返回值(部分)替换
dealsea
函数。当您稍后(在后续迭代中)再次尝试调用该函数时,您得到的是较早的结果(列表),而不是您想要的函数


解决方案并不复杂,只需为函数或列表选择不同的名称即可。代码后面部分中的
dealsf
也存在同样的问题。它还没有引发异常,因为您没有找到它,但是如果您只修复
dealsa
,您将在那里开始崩溃。

显然
dealsa
是一个列表,您不能像函数一样调用列表。但是您没有显示定义了
dealsa
的代码的相关部分,因此我们不能告诉您更多。假设您实际上有一个名为
dealsa
的函数,该函数返回一个元组,其中第二项是一个列表,如果您没有将该列表命名为与函数相同的名称,则会有所帮助。请提供预期的结果。显示中间结果与预期结果的偏差。我们应该能够将单个代码块粘贴到文件中,运行它,并重现您的问题。这也让我们在你的背景下测试任何建议。哦,我甚至没有意识到这是一个问题。抢手货它现在正在工作。我没有包括函数,因为它们使用特定于程序api的库。我不知道他们是否会有帮助,如果没有凭据,您无法运行代码。下面是用于记录的函数之一。它们都是类似的def dealsf(bot_id):error,bot_info=p3cw.request(entity=“deals”,action=”“,payload={“limit”:1000,“offset”:0,“bot_id”:bot_id,“scope”:“finished”,})返回错误,bot_info
error, dealsa = dealsa(botid)