Python Forum
if /else statement not executing correctly
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if /else statement not executing correctly
#1
I am trying to get a list of groups in an aws account. Then allow a user to add the groups to a user name, until the user enters quit:
group_list = client.list_groups()
all_groups = []
for group in group_list['Groups']:
    group_name = group['GroupName']

all_groups.append(group_name)
    for group_name in all_groups:
        print(group_name)

add_group_name = ''
while add_group_name != 'quit':
    add_group_name = input("Enter the group name to add to user %s: " % user_name)
    if add_group_name == 'quit':
    break
else:
    print("Add user to group.")
    client.add_user_to_group(GroupName=add_group_name,UserName=user_name)
What happens is that the line:
client.add_user_to_group(GroupName=add_group_name,UserName=user_name)
never gets executed. How can I change this so thtat this line gets executed? Also is there a better way of doing this?
Reply


Messages In This Thread
if /else statement not executing correctly - by bluethundr - Apr-15-2019, 08:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  If statement not working correctly? MrKnd94 2 843 Nov-16-2022, 02:49 AM
Last Post: deanhystad
  Why doesn't my loop work correctly? (problem with a break statement) steckinreinhart619 2 3,227 Jun-11-2019, 10:02 AM
Last Post: steckinreinhart619
  if-elif-else statement not executing laila1a 4 3,037 Jan-05-2019, 02:22 PM
Last Post: buran
  'else' statement not executing sparkz_alot 3 3,900 Jul-20-2017, 01:00 AM
Last Post: ichabod801
  print() statement not executing.. bmohanraj91 3 3,690 May-01-2017, 03:56 PM
Last Post: Ofnuts

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020