python - 类型错误 : range() integer end argument expected, 已获取 int

标签 python qt integer int squish

我使用 Squish 6.4.2 来测试我的 Qt 应用程序,使用 Python 2.7.10 作为测试脚本语言,并在尝试使用 range() 函数时收到以下错误消息:

类型错误:range() 需要整数结束参数,已得到 int。

这是一个小代码示例和我在 Squish 中的输出:

def main():
    test.log(str(range(4)))
    test.log(str(range(int(4))))
[0, 1, 2, 3]
Error: Script Error
    Detail: TypeError: range() integer end argument expected, got int.

如您所见,range(4) 有效,但 range(int(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]
>>>

此外,当我将整数与强制转换的 int 进行比较时,Squish 中的比较结果是错误的。例如在 Squish 中:

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

给出

False
True

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

最佳答案

Squish 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在 Squish 手册中。

关于python - 类型错误 : range() integer end argument expected, 已获取 int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55372342/

相关文章:

javascript - 我很难定义和显示用户输入的字符串数组的平均值并显示 3.4 以上的所有数字

python - 如何打印 div data-reactid?

python - 可选参数和描述符实例

Qt QListWidgetItem 多行

c++ - OpenGL 翻译不生效

java - 在 Java 中将 long 转换为 byte

ruby-on-rails - 在 Ruby on Rails 中测试字符串是否为数字

python - 资源管理器右键单击上下文菜单与 python?

python - 在 Django 中使用 for 循环将数据插入谷歌可视化条形图图表

c++ - 从 qml 访问 Qt 2 或 3d bool 列表