Python (botto3) question

Asked 1 weeks ago, Updated 1 weeks ago, 1 views

for re in response1['Reservations']:
    for ins in re['Instances']:                
        for sg in ins['SecurityGroups']:
            instance_id = ins.get('InstanceId')       
            sg_id = sg.get('GroupId')
            print(instance_id)
            print(sg_id)        
            client.modify_instance_attribute(
                Groups=[sg_id],
                InstanceId=instance_id,
            )

What's important here is sg_id, and up to print(sg_id) you'll get the amount of data I want However, Groups=[sg_id] at the bottom, there is a phenomenon where only the last value is taken. Please help me!

python

2022-09-20 13:14

1 Answers

There's only one reason we can't solve this.

Because I don't understand what a for statement is.

I want you to run the following code and think about why the value a came out like this, and how do you get multiple values?

for i in range(50):
    a = i
print(a)

for i in range(50):
    if i == 29:
        a = i
print(a)


2022-09-20 13:14

If you have any answers or tips


© 2022 pinfo. All rights reserved.