python determine whether the characters in the file, there is no add

ef Dns_list (Dns_file, * Dns_addr): # Dns_file: file path; Dns_addr: String (-s)

    for Dns_IP in Dns_addr:

        Dns_existence=""

        with open(Dns_file,"r") as foo:

            for line in foo.readlines():

                if re.match('^nameserver(\s)*'+Dns_IP+'$',line):

                    global asd

                    Dns_existence = "yy"

            if  Dns_existence != "yy":

                w=open(Dns_file,"a")

                w.write("nameserver "+Dns_IP)

                w.write("\n")

                w.close()

    return

Guess you like

Origin blog.csdn.net/qq_35751770/article/details/93734479