1

Hi i want to write in excel file output from my program in Python. This program ping every ip adress from txt file.

This is my code:

import os

with open("ip.txt", "r+") as ips_file:
    ips = [ip.strip() for ip in ips_file.readlines()]

with open("IPsCheck.txt", "w") as available_ips_file:
    for ip in ips:
        response = os.system('ping {} -n 2 -w 2'.format(ip))
        if response == 0:
            available_ips_file.write(ip + "\n")
        else:
            print('server {} not available'.format(ip))

  • 1
    https://stackoverflow.com/questions/13437727/how-to-write-to-an-excel-spreadsheet-using-python – Sean C Jun 21 '22 at 16:47

1 Answers1

0

I would recommend using the pandas. This package has a to_excel method for data. Take a look at the documentation.

emmacb
  • 99
  • 6