Sep-24-2022, 04:22 PM
Hi guys another day another issue.. So I have this code
from contextlib import suppress from ipaddress import IPv6Address, ip_address def make_ipv4_set(file_like): results = set() for line in map(str.strip, file_like): addr = None with suppress(ValueError): addr = ip_address(line) if isinstance(addr, IPv6Address): continue results.add(line) return results with ( open("ip1_file.txt") as ip1_file, open("ip2_file.txt") as ip2_file, ): ip1_set = make_ipv4_set(ip1_file) ip2_set = make_ipv4_set(ip2_file) results = ip1_set - ip2_set for ip in results: print(ip)Which does the work like i expect it to but what I need is instead of it printing the output in a terminal I want to output the result in a text file. So can anyone help me with the code. Much appreciated thank you