In my python class I have created a nested for loop, the script and the output should be pretty straight forward. What is not straight forward is how do I fix this!!
I have googled for hours looking at examples of other nested for loops, but have not found any similar to mine to help me understand this problem.
Here is the entire script:
LIST = "list.txt"
USERNAME = "users.txt"
# Open the files to read from
listtxt = open(LIST,"r")
userstxt = open(USERNAME,"r")
# For each user in users.txt
for USER in userstxt:
print ("Started new user %s" % USER)
for PASSWD in listtxt:
print USER + ", " + PASSWD
OUTPUT
Started new user user1
user1
, pass1
user1
, pass2
user1
, pass3
user1
, pass4
user1
, pass5
Started new user user2
Started new user user3
Started new user user4
Started new user user5
Do you see the problem already? The problem is it iterates thru the first user correctly, but on all subsequent users it only goes thru the first (user) loop but does not execute the password loop
list.txtfile into a list, then loop over that list.