TypeError:应为range()整型结束参数,已输入

2024-05-23 19:17:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用Squish6.4.2测试我的Qt应用程序,使用python2.7.10作为测试脚本语言,在尝试使用range()函数时收到以下错误消息:

TypeError: range() integer end argument expected, got int.

下面是一个小代码示例和我的Squish输出:

def main():
    test.log(str(range(4)))
    test.log(str(range(int(4))))
^{pr2}$

如您所见,range(4)起作用,而{}不起作用

我尝试在Squish应用程序附带的Python版本的Python控制台中运行相同的代码,range()调用都起作用。在

Python 2.7.10 (default, May 23 2015, 09:44:00) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> range(4)
[0, 1, 2, 3]
>>> range(int(4))
[0, 1, 2, 3]
>>>

另外,当我把整数与一个casted int进行比较时,这个比较结果是错误的。例如,挤压:

def main():
    test.log(str(7<4))
    test.log(str(7 < int(4)))

给予

False
True

但是在Python控制台中,结果是正确的。在


Tags: 函数代码testlog应用程序消息maindef
1条回答
网友
1楼 · 发布于 2024-05-23 19:17:58

压扁int与Python int不同:

Squish's int represents the Squish type for an integer in the wrapper's C and C++ code.

Like the other hidden symbols, to access Python's int() function one can use it from the package __builtin__ (Python 2) or builtins (Python 3).

其他类型也不同

Squish's int vs. Python's int

或者更一般地说是挤压手册中的Python Notes。在

相关问题 更多 >