Object is not subscriptable in python

时间:2017-06-15 10:05:54

标签: python

I have the following code:

c = containers[0].resources.limits['cpu']

cpulimit = int(c.split("m")[0])

this works, but this code:

int(containers[0].resources.limits['cpu'].split("m")[0])

gives me :

TypeError: 'type' object is not subscriptable

containers[0].resources.limits has type dictionary: i.e limits contains { "cpu": "500m" , "memory": "512Mi"}

1 个答案:

答案 0 :(得分:-1)

This should work:

cpulimit = int((containers[0].resources.limits['cpu']).split("m")[0])

Since you are using containers instead of container in your example.