如何在python 2.7中的for循环中执行多个if语句?

时间:2017-08-09 22:07:26

标签: python-2.7

我在循环中有2个if语句'但由于某种原因,第二个if语句没有被执行,我无法弄清楚原因。

这是我的代码:

def get_tag_value(instance_id, tag, region):
    ec2 = boto3.resource('ec2', region)
    ec2_instance = ec2.Instance(instance_id)

    for tags in ec2_instance.tags:
        if tag == tags['Key']:
            #return tags['Value']
            tag=tags['Value']
            return tags['Value']
            return None
    return None




    for region in response['Regions']:
        if region['RegionName'] not in regions:
            continue

        try:
            response = ec2.describe_instances()
            start_list = []
            stop_list = []
            tag = ""

            for reservation in response['Reservations']:
                for instance in reservation['Instances']:
                    state=(instance['State']['Name'])

                    auto_start = get_tag_value(instance['InstanceId'], 'auto:start', region['RegionName'])
                    auto_stop = get_tag_value(instance['InstanceId'], 'auto:stop', region['RegionName'])
                    print "start schedule is", auto_start

                    if auto_start:
                        print "Autostart is ", auto_start
                    else:
                        print "no auto start"

                    if auto_stop:
                        print "Autostop is ", auto_stop
                    else:
                        print "no auto stop"

仅执行第一个if语句的结果。有人可以告诉我这里有什么问题吗?

任何建议表示赞赏, 谢谢

0 个答案:

没有答案