CSV Showcase

  • ZorkFanDM

    ZorkFanDM - 2010-09-23

    This is a quick script to make reading through CSVs in notepad++ easier.
    I often just need to quickly look down for a value, and opening Excel or OOCalc is time consuming.

    a = [[] for x in editor.getLine(1).split(",")]
    def csv_to_list(cont, l_num, tot_lines):
        cont = cont.split(",")
        for n in range(len(cont)): a[n].append(cont[n].replace("\r\n", ""))
    aLens = [max([len(x) for x in a[y]]) for y in range(len(a))]
    def form_line(l_num):
        txt = "".join([a[x][l_num].ljust(aLens[x]+1) for x in range(len(aLens))])
        txt = txt + "\r\n"
    for l in range(len(a[0])-1): editor.addText(form_line(l))
  • vos causa

    vos causa - 2011-03-08

    I received an error while trying your script :

    Python 2.7.1 (release27-maint-npp, Feb  6 2011, 16:58:20)
    Initialisation took 609ms
    Traceback (most recent call last):
      File "C:\Users\Robert Vos\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\csvsplit.py", line 6, in <module>
      File "C:\…\AppData\Roaming\Notepad++\plugins\Config\PythonScript\scripts\csvsplit.py", line 4, in csv_to_list
        for n in range(len(cont)): a.append(cont.replace("\r\n", ""))
    IndexError: list index out of range

  • Dave Brotherstone

    That appears to occur if you've got one (or more) lines with a different number of fields in - bear in mind also that the script doesn't cope with quoted data - so


    The last "field" (jones,dave), would be treated as two.  Perhaps someone, maybe the original author, can suggest an improvement to the script…


  • vos causa

    vos causa - 2011-03-09

    Thanks for the reply. My data contains variable lenght records (a variable number of columns) and is quoted.
    I have tried to solve it with Notepad, making use of  Text Fx edit. Bbut (I think) because I use UTF-8 encoded data, the aligment function (Line up by multiple lines) does not work correctly.
    I have solved the readability with: uniCSVed, but now I miss my other Notepad++ functions.


Log in to post a comment.