I am trying to parse a CSV file, which has multi-line string in one of the fields (field 6). I can read the field fine, but when I try to process each line from that field, it gives me one character on a new line at a time instead of a line at a time. Any ideas what am I doing wrong?
def lookup(ip, ranges_csv):
with open(ranges_csv, 'r') as csvIN:
l = csv.reader(csvIN, dialect='excel')
next(l) # Skip the header row
for row in l:
for subnet in row:
well it makes sense, since each element in row is a string, and when you iterate a string you get one character at a time.
you can split the string to get your desired result:
for row in l: for subnet in row.split('\r\n'): print(subnet)
\r\n means new line in windows, if you are using linux it should be only \n.