【问题标题】:TypeError: 'numpy.int64' object is not callable, whenever I call len function in python?TypeError:'numpy.int64'对象不可调用,每当我在python中调用len函数时?
【发布时间】:2021-01-19 21:03:57
【问题描述】:

每当我尝试在我的代码中使用 len 函数时,我都会收到此错误?

long_trade={}
short_trade={}
long_trade['total_long']=get_total_long(long_df,len(long_df))
short_trade['total_short']=get_total_short(short_df,len(short_df))

print(short_trade)
print(long_trade) 

错误

> TypeError                                 Traceback (most recent call
> last) <ipython-input-37-619a2cc53415> in <module>()
>       2 long_trade={}
>       3 short_trade={}
> ----> 4 long_trade['total_long']=get_total_long(long_df,len(long_df))
>       5 short_trade['total_short']=get_total_short(short_df,len(short_df))
>       6 
> 
> TypeError: 'numpy.int64' object is not callable

【问题讨论】:

  • 您将不得不提供更多代码让我们能够重现或解决您的问题。但是从外观上看,您似乎在某处命名了一个变量len
  • 请提供预期的MRE。显示中间结果与预期结果的偏差。我们应该能够将您的代码块粘贴到文件中,运行它并重现您的问题。
  • 抱歉,我无法重现部分代码。由于未披露????

标签: python jupyter-notebook


【解决方案1】:

get_total_longlen 之间的一个被意外分配给一个整数,无论​​您认为它们都应该是函数,因此您正在调用它们(通过使用括号)

很可能在您的代码中某处有这样一行:

len = some expression which returns a numpy.int64

get_total_long = some expression which returns a numpy.int64

【讨论】:

    猜你喜欢
    • 2013-07-19
    • 2018-03-09
    • 2013-05-05
    • 2020-09-11
    • 1970-01-01
    • 2019-05-23
    • 2022-12-14
    • 2020-06-27
    • 2018-02-01
    相关资源
    最近更新 更多