[英]Why do I get the error "TypeError: 'NoneType' object is not subscriptable" in python?
I'm iterating over a list of tuples and assigning the values in the tuple to a string.我正在遍历一个元组列表并将元组中的值分配给一个字符串。 Why do i get an Error here?为什么我在这里得到一个错误?
for x in falsy_instances:
instance_list += 'InstanceId: ' + x[0] + ' -> ' + str(x[1]) + 'h\n'
My list of tuples looks like this:我的元组列表如下所示:
[('i-048debd640ac2dc2f', 2303), ('i-097fc609b8b4dfd56', 5177), ('i-0ba0bb267b314277e', 1913), ('i-09ee8e071c20a7c3d', 4030), ('i-061a71ea52275f17b', 1406), None, ('i-02a7c2e0335dc7b3c', 144), ('i-02e7f7f17726ca422', 2538), ('i-0f18e9ae7728be9b3', 2198)]
The 6th element in your list is None
:列表中的第 6 个元素是None
:
[('i-048debd640ac2dc2f', 2303),
('i-097fc609b8b4dfd56', 5177),
('i-0ba0bb267b314277e', 1913),
('i-09ee8e071c20a7c3d', 4030),
('i-061a71ea52275f17b', 1406),
None, # <-- Here
('i-02a7c2e0335dc7b3c', 144),
('i-02e7f7f17726ca422', 2538),
('i-0f18e9ae7728be9b3', 2198)]
for x in falsy_instances:
if x is not None:
instance_list += 'InstanceId: ' + x[0] + ' -> ' + str(x[1]) + 'h\n'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.