python - Python 中是否有 static_cast 关键字或标准方法?

标签 python c++ static-cast

我得到了以下代码:

def DisplayListCurveKeys(pCurve, pProperty):
    lKeyCount = pCurve.KeyGetCount()

    for lCount in range(lKeyCount):
        lKeyValue = static_cast<int>(pCurve.KeyGetValue(lCount))
        lKeyTime  = pCurve.KeyGetTime(lCount)

        lOutputString = "            Key Time: "
        lOutputString += lKeyTime.GetTimeString(lTimeString)
        lOutputString += ".... Key Value: "
        lOutputString += lKeyValue
        lOutputString += " ("
        lOutputString += pProperty.GetEnumValue(lKeyValue)
        lOutputString += ")"

        print(lOutputString)

它使用 static_cast<int>表达式,看起来像来自 C++ .它在 Python 中有效吗?

最佳答案

不,没有 static_cast在 Python 中。

在您展示的示例中,pCurve.KeyGetValue(lCount) (其类型在代码中不明显)被转换为 int .您可以尝试更换 static_cast<int>只有 int .如果原始值是某种标量数或表示整数的字符串,这将起作用。

例如int('23') == 23将评估为 True在 Python 中。

如果你能提供更多关于表达式类型的信息 pCurve.KeyGetValue(lCount)如果 int(...) 可能会想出一个解决方案方法不起作用。

关于python - Python 中是否有 static_cast 关键字或标准方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46606400/

相关文章:

python - 获取明年 1 月 1 日

python - 为什么将文本写入文件时会出现括号?

python - 根据单列的值将值添加到数据框列

python - 在列表理解中将字符串添加到字典

c++ - 使用 Opencv 将姿势值实时写入文本文件

c++ - 使用 static_cast 实现的转换运算符

c++ - 将 time_t 转换为 int

c++ - OpenGL 累积缓冲区不工作

c++ - 防止 Xcode 9.4 无限期索引的技巧

c++ - 枚举的 reinterpret_cast 错误