2017-09-27 41 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]