list - Creating new text files with names from an array in Python -


i'm rusty in python (and skills, when not rusty, rudimentary @ best), , i'm trying automate creation of config files. i'm trying take list of mac addresses (which manually inputted user), , create text files mac addresses names, .cfg appended end. i've managed stumble around , accept user input , append array, i've ran stumbling block. i'm in infant phase of program, it's start. here's i've got far:

def main():      print('welcome config tool!')      mactable = []      numofmacs = int(input('how many mac addresses provisioning today? '))      while len(mactable) < numofmacs:      mac = input("enter mac of phone: "+".cfg")      mactable.append(mac)        open(mactable, 'w') main() 

as can seen, i'm trying take array , use in open command filename, , python doesn't it.

any appreciated!

the first problem can see indentation of while loop. have:

while len(mactable) < numofmacs: mac = input("enter mac of phone: "+".cfg") mactable.append(mac) 

while should be:

while len(mactable) < numofmacs:     mac = input("enter mac of phone: "+".cfg")     mactable.append(mac) 

as files, need open them in loop too, either:

for file in mactable:     open(file, 'w') 

or can in while well:

while len(mactable) < numofmacs:     mac = input("enter mac of phone: "+".cfg")     mactable.append(mac)     open(mac, 'w')     mactable.append(mac) 

another thing might want change input processing. understood want read mac adresses user , name config files <mac>.cfg. suggest change

mac = input("enter mac of phone: "+".cfg") 

to

mac = input("enter mac of phone:") filename = mac + ".cfg" 

and need decide if want have mac adresses or filenames in mactable


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -