I'm trying to get Python to concatenate multiple lists in multiple new files. At the end of each "go" I would write the output into a file. I would need this to generate multiple configuration files where the user/pass/mac would be changing, while most other stuff would stay the same.
I tried to use the for loop to perform this, but I can not get it to work. In the output file there would be some rows that would be the same across all the files and some rows where the data would be provided from two separate lists.
Output should look something like this (the file in the end will consist of 100+ rows):
Initial data:
user=["user1","user2","user3"]
password=["pass1","pass2","pass3"]
mac=["mac1","mac2","mac3"]
Resulting files:
mac1.cfg:
#configuration
username= user1
password= pass1
server= 1.1.1.1
option1= enable
mac2.cfg:
#configuration
username= user2
password= pass2
server= 1.1.1.1
option1= enable
and so on...
I’m sure that this can be done in many other (easier) ways, but I would like to solve the problem by using python. So far (in my limited python skill) I first tried to get out a single batch of data and this works. When I try to use the for loop to achieve the same thing for all the “sets” I get stuck.
Single batch code looks like this:
user=["user1","user2","user3"]
password=["pass1","pass2","pass3"]
mac=["mac1","mac2","mac3"]
file1 = open(mac[0]+".cfg", "x")
line1=("#configuration")
line2=("username= "+user[0])
line3=("password= "+password[0])
line4=("server= 1.1.1.1")
line5=("option1= enable")
text=line1+"\n"+line2+"\n"+line3+"\n"+line4+"\n"+line5
file1.writelines(text)
file1.close()
If I try to multiplicate the logic with a for loop I get stuck... can you please help me out?