2017-09-27 40 views
0

我仍在学习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] 

我只是不知道如何。

+0

'shotLengthInt [0] + = 1' – AK47

+0

你确定你真的想有你'int'在列表中?如果没有,你可以简单地在开头做:'lastFrame = int(shotLength [-1])+ 1';否则你可以使用'shotLengthInt [0] + = 1'(如@ AK47建议),它只是感觉过于复杂...... – mapofemergence

+0

@mapofemergence谢谢!这实际上是完美的。 – dave

回答

2

时也删除list()您可以编辑如下:

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

我们可以通过lambda函数来图,来实现它:

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

你可以使用'shotLengthInt = map(lambda x:int(x)+ 1,shotLength)' – AK47

+0

是的你的权利,它不必再次转换为列表,谢谢,我会编辑ans。 – dalonlobo

1

你的价值包含在列表中(注意括号),所以更新1此值,则需要引用列表的第一指标和增量由1

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

你可以分配值shotLengthInt

>>> shotLength = [1090.0] 
>>> shotLength 
> [1090.0] 
>>> shotLengthInt = map(int, shotLength) 
>>> shotLengthInt 
> [1090]