搜索列表长度时出错

问题描述 投票:0回答:1

[编辑:解决了,我用错误的输入参数从代码中的另一个地方调用相同的函数,创建此错误]

我是python的新手,经过一番搜索,我决定发布我的问题..

我的函数将* args作为输入:可变数量的列表

在这个函数中,我使用for循环来读取所有列表并尝试获取len(each_list)。然后我得到错误TypeError:'numpy.float64'类型的对象没有len()

我试图自己找到问题,但我不理解这种行为

如果我做:

def myfunction(* args):
    for p in args:
        print(isinstance(p, list))
        print(type(p))
        print(p)

我会得到:True + class'list'+ [value1,value2,... etc]

但是,如果我添加一行来获得长度(最后一个)

def myfunction(* args):
    for p in args:
        print(isinstance(p, list))
        print(type(p))
        print(p)
        a = len(p)

我会得到:False + class'numpy.float64'+错误(我知道它不可迭代)

我将该函数称为:

All_lists = [list1, list2, list3]
myfunction(All_lists)
# I've also tried myfunction(*All_lists)

谢谢您的帮助

python-3.x
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.