I'm parsing a CSV file using python. I've two problem:
- My list is being treated as string
- Is there a way to make my parsing more "elegant"
Example CSV file
Name, Address
host1,['192.168.x.10', '127.0.0.1']
host2,['192.168.x.12', '127.0.0.1']
host3,['192.168.x.14', '127.0.0.1']
My code:
with open('myFile') as file:
csv_reader = csv.DictReader(csv_file, delimiter=',')
for row in csv_reader:
for i in row['Address'].strip("][").replace("'","").split:
if('192.168' in i):
break
print(row[host], i)
Output:
host1 192.168.x.10
host2 192.168.x.12
host3 192.168.x.14