简体   繁体   English

错误类型:范围()预期的整数结束参数,得到了LP_c_ulong

[英]Error type: range() integer end argument expected, got LP_c_ulong

I got this error when I try to use 'slots_num' as a parameter in range(): 当我尝试使用'slots_num'作为range()中的参数时出现此错误:

        slots_num = pointer(c_uint32())
        slots = pointer(c_uint32())

        if self.mgetBusSlotsFunc(self.mf, slots_num, slots) != 0:
            raise Exception("Failed to get slots")

        print(devAddr)

        for x in range(0, slots_num):
            print(slots[x])

What I did wrong? 我做错了什么?

The range built-in function expects integers as its arguments , range内置函数期望整数作为其参数

The arguments to the range constructor must be integers (either built-in int or any object that implements the index special method). 范围构造函数的参数必须是整数(内置int或实现索引特殊方法的任何对象)。

but you have provided a pointer instance. 但是您提供了一个指针实例。

>>> import ctypes
>>> p = ctypes.pointer(ctypes.c_uint32(2))
>>> for i in range(0, p):print(i)
... 
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'LP_c_uint' object cannot be interpreted as an integer

You need to dereference the pointer to get the corresponding value. 您需要取消引用指针以获取相应的值。

>>> d = p.contents.value
>>> d
2
>>> for i in range(0, d):print(i)
... 
0
1

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 range()整数结束参数,已获得Tag - range() integer end argument expected, got Tag TypeError:range()整数终止参数,在Python中得到了str - TypeError: range() integer end argument expected, got str In Python TypeError:range()期望整数结束参数,浮点数? - TypeError: range() integer end argument expected, got float? Python TypeError: range() integer 期望结束参数,得到浮点数 - Python TypeError: range() integer end argument expected, got float TypeError:range()整数结束参数应为int - TypeError: range() integer end argument expected, got int Python TypeError:range()整数终止参数,浮点型 - Python TypeError: range() integer end argument expected, got float 已经显示了玩家卡值,但是有一个错误range()整数结尾参数,已经得到列表 - Already display the player card value but have an error range() integer end argument expected, got list Python ctypes 错误 - TypeError: an integer is required (got type LP_c_long) - Python ctypes error - TypeError: an integer is required (got type LP_c_long) Python TypeError:range()整数终止参数,浮点型。 具有拟合功能 - Python TypeError: range() integer end argument expected, got float. with fit function XGBRegressor .fit()方法TypeError:range()预期的整数结束参数,浮点型 - XGBRegressor .fit() method TypeError: range() integer end argument expected, got float
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM