0

我尝试获取特定的 AMI 列表并将其存储在数组列表中。

usubuntuamilist = {}
for i, image in enumerate(conn.get_all_images()):
    if image.location.startswith("ubuntu-images-us/ubuntu-lucid-10.04-i386-serve"):
        print "%s - %s" % (i, image.name)
        usubuntuamilist[i] = image.name

如何检查阵列位置是否有现有的 AMI?

我检查使用这种方式,但它不起作用

userinput = raw_input("Select: ")

try:
    usubuntuamilist = usubuntuamilist[userinput]
    print usubuntuamilist.location
except:
    print "Does not exist!"

替代方案我也尝试使用这种方式进行检查。两种方式都行不通

if usubuntuamilist[input] is not None:
    print usubuntuamilist[input]
else:
    print "Does not exist"

有任何想法吗?如果有更好的选择来解决这个问题,我想听听!

4

1 回答 1

1

Why not just:

if image.location.startswith("ubuntu-images-us/ubuntu-lucid-10.04-i386-serve"):
        # As before...
else:
        usubuntuamilist[i] = None

Then, checking is the image name is None is simple, no?

于 2011-10-13T14:38:02.377 回答