Created
January 8, 2019 17:25
-
-
Save gil-obradors/87759598f594a295429fcf00b015d976 to your computer and use it in GitHub Desktop.
Play python3 csv ipaddress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import csv,ipaddress | |
with open('IPv4Address.csv', newline='') as csvfile: | |
data = list(csv.reader(csvfile)) | |
print(data[1][0]) | |
print(type(data)) | |
print(str(ipaddress.IPv4Address(3232235521))) | |
for i in data: | |
i[0] = str(ipaddress.IPv4Address(int(i[0]))) + "/32" | |
i[2] = "Deprecated" | |
del i[3] | |
if len(i[1]) == 0: | |
i[1] = "indefinit" | |
with open('conversio.csv', 'w') as csvfile2: | |
wr = csv.writer(csvfile2, doublequote=False, delimiter=',') | |
for linia in data: | |
wr.writerow(linia) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment