lundi 18 septembre 2017

Reduce array and why if comparison does not work with or

Hi Python community,

  I created a program that reads a VPN output and it return the crypto maps with no encryption, but I have concern in the following things:

1.- Is is possible to reduce this array:

h.write(all_vpns[n-5]+all_vpns[n-4]+all_vpns[n-3]+all_vpns[n-2]+all_vpns[n-1]+all_vpns[n]+all_vpns[n+1]+"\n\n")

To something like all_vpns[n-5]:all_vpns[n+1] or all_vpns[n-5]-all_vpns[n+1]

2.- There is a function that I used to remove all the lines from the file , which works good when there is only one rule in the if statement but when I add 2 it doesn't work:

with open(in_filename) as infile, open("clean_vpn.txt", "w") as outfile:
    for line in infile.readlines():
        if line!='\n':
            outfile.write(line)

If in the if I add another argument it doesn't work if line!='\n' or line!=' \n':

Does someone know why the or is not working but as I mentioned before if I only have either argument it works fine for that statement but not both with the or.

Thanks again

Aucun commentaire:

Enregistrer un commentaire