Good day all,
I am trying to write a python script that picks up IP address(es) from a textfile, check if the IP addresses already present in CSV file, if IP address is already present then do nothing (pass), if the IP is not present in the CSV file then append the IP address in the CSV file.
I can add the IP addresses to the CSV file but I am not able to get my head around with how to check if the IP address is already present in the file.
if os.path.isfile('IP_file.txt'):
logfile = open('IP_file.txt', 'r')
csv_file = open('csv_file.csv', 'ab')
for line in logfile:
if line in csv_file: # This is not working
pass
else:
csv_file.write(line)
csv_file.close()
logfile.close()
else:
print('No file with filename ' logfile 'created')
I also tried to use the CSV module but no luck. Any help is much appreciated.
IP_file.txt?