玛雅Python:如何将列表转换为整数
问题描述:
我仍在学习python,请耐心等待。 我得到关键帧1000和2000玛雅Python:如何将列表转换为整数
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
>>> shotLength = [1090.0]
>>> shotLength
> [1090.0]
>>> shotLengthInt = map(int, shotLength)
>>> shotLengthInt
> [1090]
'shotLengthInt [0] + = 1' – AK47
你确定你真的想有你'int'在列表中?如果没有,你可以简单地在开头做:'lastFrame = int(shotLength [-1])+ 1';否则你可以使用'shotLengthInt [0] + = 1'(如@ AK47建议),它只是感觉过于复杂...... – mapofemergence
@mapofemergence谢谢!这实际上是完美的。 – dave