Y
You don't have to complicate your existence by reinventing the wheel. There are already file formats to save the information very similar to what you propose. For example, with a small syntax change in your file login.txt You can make it YAML valid. The only necessary change is to use simple quotes instead of doubles (to avoid having problems with character \ that appears within some of your chains), and remove the assignments to user1, user2, etc. changing them by scripts.I mean, it's this other way:# Contenido del fichero login.txt
- ['10.0.0.3','Root','*****','/usr/amat','C:\Users\becario2adm','yyyymmdd']
- ['10.0.0.4','Administrador','*******','/zzz','C:\Users\becario2adm','yyyy_mm_dd']
- ['10.0.0.5','Administrador','*******','/','C:\Users\becario2adm','yyyy_mm_dd']
If you are willing to admit as valid this input format, which I repeat is practically identical to the one you propose in the question, then you do not need to schedule any loop to perform the reading.Just have the library installed. yaml and do:import yaml
with open("login.txt") as f:
data = yaml.safe_load(f)
And that's it. In data You have a list with as many elements as lines had your file. Each element is another list whose elements are ip, username, key, folder, etc.For example, the next itera loop on that list and displays the IP and folderfor elemento in data:
print(elemento[0], elemento[3])
and come out.10.0.0.3 /usr/amat
10.0.0.4 /zzz
10.0.0.5 /
I guess it won't be hard for you to adapt this code so that instead of printing these things on screen use them to make ftp connections or whatever you want to do with that information.