Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Write list of list to CSV?
#8
(Feb-24-2019, 08:17 AM)buran Wrote:
(Feb-24-2019, 07:58 AM)searching1 Wrote: After running this from my original file which Im working, It's not writing any data on the CSV, maybe u have encountered/ any idea with this?
I am not sure I understand this

There no data after running the script. no trace or anything will running. It's just no data can be seen once you open the csv file.

Posting my config. maybe you can see something unusual. Thanks

import re, base64, os, sys, subprocess, csv, itertools

with open('list.txt') as csvfile:
    rilist = csv.reader(csvfile, delimiter=',')
        
#Put the data from excel here
    rtrlist = []
    intlist = []
    ilist =[]
    dlist = []
    blist = []
        
#Action - Put the data from excel to variable[list]
    for col in rilist:
        rtr = col[0]
        intf = col[1]

        rtrlist.append(rtr)
        intlist.append(intf)
##    csvfile.close()
##    print(rtrlist,"\n",intlist)

    #Change Directory
    os.chdir("/rs/configs")
    print("pwd=%s" % os.getcwd())

    ## START OF THE LOOP ##
    for a,b in zip(rtrlist, intlist):
        srtr = a.strip()
        sint = b.strip()
        subint = re.sub("\d+\/*", "", sint)
        print ("Processing.... ",srtr,sint)
        proc = subprocess.Popen(("grep", "-A11", "interface %s"%sint, srtr), stdout = subprocess.PIPE)  
        lbl = proc.communicate()[0]
        teststr = lbl.decode()
        print (teststr)
        
        #SEARCH INTERFACES
        ipat = re.findall(r"(?P<intrfname>%s+\d+\/.*)" %subint, teststr)
        ilist.append(ipat)
        print ("List of Interface: \n",ipat)

        #SEARCH INTERFACE DESCRIPTION
        dpat = re.findall("(?<=description\s)([A-Za-z0-9]+\;.*)", teststr)
##        dpat = ','.join(ddpat)
        dlist.append(dpat)
        print ("\nDescription: ",dpat)

        #GET BUNDLE ID / CHANNEL GROUP
        bbpat = re.findall("(?<=bundle id\s)+\d+", teststr)
        bpat = ','.join(bbpat)
        blist.append(bpat)
        print ("\nBundled: ",bpat)

print ("\nRTR List: ",rtrlist)
print ("\nINT List: ",ilist)
print ("\nDESC List: ",dlist)
print ("\nBUN List: ",blist)

rtrlist = [[ele] for ele in rtrlist]
dlist = [[ele] for ele in dlist]

## EXPORT AS CSV
with open('intlist.csv', 'w', newline='') as updatecsv:
    write = csv.writer(updatecsv, delimiter=',',lineterminator='\n')
    for cols in zip(rtrlist,ilist,dlist):
        rows = itertools.zip_longest(*cols, fillvalue='')
        write.writerows(rows)
updatecsv.close()
print ("\n Done...csv file has been updated")
Reply


Messages In This Thread
Write list of list to CSV? - by searching1 - Feb-24-2019, 01:13 AM
RE: Write list of list to CSV? - by Larz60+ - Feb-24-2019, 01:28 AM
RE: Write list of list to CSV? - by Larz60+ - Feb-24-2019, 01:49 AM
RE: Write list of list to CSV? - by searching1 - Feb-24-2019, 01:50 AM
RE: Write list of list to CSV? - by buran - Feb-24-2019, 06:42 AM
RE: Write list of list to CSV? - by searching1 - Feb-24-2019, 07:58 AM
RE: Write list of list to CSV? - by buran - Feb-24-2019, 08:17 AM
RE: Write list of list to CSV? - by searching1 - Feb-24-2019, 08:28 AM
RE: Write list of list to CSV? - by buran - Feb-24-2019, 08:43 AM
RE: Write list of list to CSV? - by searching1 - Feb-24-2019, 09:03 AM
RE: Write list of list to CSV? - by buran - Feb-24-2019, 09:10 AM
RE: Write list of list to CSV? - by searching1 - Feb-24-2019, 09:33 AM
RE: Write list of list to CSV? - by buran - Feb-24-2019, 09:37 AM
RE: Write list of list to CSV? - by searching1 - Feb-24-2019, 06:41 PM
RE: Write list of list to CSV? - by buran - Feb-24-2019, 06:43 PM
RE: Write list of list to CSV? - by SmartGrid - Feb-24-2019, 07:57 PM
RE: Write list of list to CSV? - by searching1 - Feb-25-2019, 03:26 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Strange behavior list of list mmhmjanssen 3 1,619 May-09-2024, 11:32 AM
Last Post: mmhmjanssen
  No matter what I do I get back "List indices must be integers or slices, not list" Radical 4 2,631 Sep-24-2023, 05:03 AM
Last Post: deanhystad
  Delete strings from a list to create a new only number list Dvdscot 8 3,373 May-01-2023, 09:06 PM
Last Post: deanhystad
  List all possibilities of a nested-list by flattened lists sparkt 1 1,793 Feb-23-2023, 02:21 PM
Last Post: sparkt
  Сheck if an element from a list is in another list that contains a namedtuple elnk 8 3,470 Oct-26-2022, 04:03 PM
Last Post: deanhystad
Question Keyword to build list from list of objects? pfdjhfuys 3 2,631 Aug-06-2022, 11:39 PM
Last Post: Pedroski55
  Split a number to list and list sum must be number sunny9495 5 3,849 Apr-28-2022, 09:32 AM
Last Post: Dexty
  How to check if a list is in another list finndude 4 9,533 Jan-17-2022, 05:04 PM
Last Post: bowlofred
  Different out when using conda list and pip list Led_Zeppelin 1 6,620 Jan-14-2022, 09:30 PM
Last Post: snippsat
  Use one list as search key for another list with sublist of list jc4d 4 3,103 Jan-11-2022, 12:10 PM
Last Post: jc4d

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020