Feb-24-2019, 09:10 AM
the only problem I see is that dlist is already list of lists. But this will not prevent writing to file (although it may be not what you want:
If you make it like this
What I try to say is if the print output is OK, then second part should work too (i.e. the lists are populated with values, not empty)
you can make opo list of lists by design, when you create it in the first place.
Output:device1,HundredGigE0/2/0/0,"['ALPHANUMERICWITHCHARAC;;;', 'ALPHANUMERICWITHCHARAC;;;', 'ALPHANUMERICWITHCHARAC;;;']"
,HundredGigE0/2/0/0.242,
,HundredGigE0/2/0/0.244 l2transport,
,HundredGigE0/2/0/1,
,HundredGigE0/2/0/0.244,
device1,TenGigabitEthernet1/1/0.138,['ALPHANUMERICWITHCHARAC;;;']
device1,TenGigE0/1/0/15,['ALPHANUMERICWITHCHARAC;;;']
note that lst column is str repr of a list.If you make it like this
import itertools import csv opo = ['device1', 'device1', 'device1'] intfname = [['HundredGigE0/2/0/0', 'HundredGigE0/2/0/0.242', 'HundredGigE0/2/0/0.244 l2transport', 'HundredGigE0/2/0/1', 'HundredGigE0/2/0/0.244'], ['TenGigabitEthernet1/1/0.138'], ['TenGigE0/1/0/15']] descname = [['ALPHANUMERICWITHCHARAC;;;', 'ALPHANUMERICWITHCHARAC;;;', 'ALPHANUMERICWITHCHARAC;;;'], ['ALPHANUMERICWITHCHARAC;;;'], ['ALPHANUMERICWITHCHARAC;;;']]# ['0/2/0/0info1', '0/2/0/0.242info2', '0/2/0/0.244info3'] opo = [[ele] for ele in opo] ## EXPORT AS CSV with open('intlist.csv', 'w', newline='') as updatecsv: write = csv.writer(updatecsv, delimiter=',',lineterminator='\n') for cols in zip(opo,intfname,descname): rows = itertools.zip_longest(*cols, fillvalue='') write.writerows(rows) updatecsv.close() print ("Done...")the output will be
Output:device1,HundredGigE0/2/0/0,ALPHANUMERICWITHCHARAC;;;
,HundredGigE0/2/0/0.242,ALPHANUMERICWITHCHARAC;;;
,HundredGigE0/2/0/0.244 l2transport,ALPHANUMERICWITHCHARAC;;;
,HundredGigE0/2/0/1,
,HundredGigE0/2/0/0.244,
device1,TenGigabitEthernet1/1/0.138,ALPHANUMERICWITHCHARAC;;;
device1,TenGigE0/1/0/15,ALPHANUMERICWITHCHARAC;;;
Note that desc values go to first three lines, I don't know if this is correctWhat I try to say is if the print output is OK, then second part should work too (i.e. the lists are populated with values, not empty)
you can make opo list of lists by design, when you create it in the first place.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs