Maya Python:如何将列表转换为整数

Maya Python: How to convert a list to an Integer

我还在学习python,请多多包涵。 我得到了关键帧 1000 和 2000 之间动画的最后一个关键帧。

shotLength = cmds.keyframe(time=(1000,2000) ,query=True)
del shotLength[:-1]
print shotLength 

结果:

[1090.0]

此时只有所需的关键帧作为值保留在列表中。 我将此值转换为整数,如下所示:

shotLengthInt = list(map(int, shotLength))
print shotLengthInt

结果:

[1090]

现在我想给这个值加上 +1,所以它看起来像这样:

[1091]

我就是想不通。

您的值包含在列表中(注意方括号),因此要将此值更新 1,您需要引用列表的第一个索引并将其递增 1

>>> shotLengthInt = [1090]
>>> shotLengthInt
> [1090]
>>> shotLengthInt[0] += 1
>>> shotLengthInt
> [1091]

shotLengthInt

赋值时也可以去掉list()
>>> shotLength = [1090.0]
>>> shotLength
> [1090.0]
>>> shotLengthInt = map(int, shotLength)
>>> shotLengthInt
> [1090]

您可以编辑以下内容:

shotLengthInt = list(map(int, shotLength))
print shotLengthInt

我们可以通过一个lambda函数来映射,实现它:

shotLengthInt = map(lambda x: int(x) + 1, shotLength)
print shotLengthInt