Screenshot

Python-DSV


Python-DSV is a Python module for importing and exporting DSV (delimiter separated values) files.  
DSV is a generalization of CSV (comma separated values).  CSV is a common file format used by many programs to import and export data.


Features:

Requirements:


Installation:


    Linux:
    Windows:

Basic use:


    from DSV import DSV

    data = file.read()
    qualifier = DSV.guessTextQualifier(data) # optional
    data = DSV.organizeIntoLines(data, textQualifier = qualifier)
    delimiter = DSV.guessDelimiter(data) # optional
    data = DSV.importDSV(data, delimiter = delimiter, textQualifier = qualifier)
    hasHeader = DSV.guessHeaders(data) # optional

If you know the delimiters, qualifiers, etc, you may skip the optional 'guessing' steps as they rely on heuristics anyway (although they seem to work well, there is no guarantee they are correct). What they are best used for is to make a good guess regarding the data structure and then let the user confirm it.

As such there is a 'wizard' to aid in this process (use this in lieu of the above code - requires wxPython):

    from DSV import DSV

    dlg = DSV.ImportWizardDialog(parent, -1, 'DSV Import Wizard', filename)
    dlg.ShowModal()
    headers, data = dlg.ImportData() # may also return None
    dlg.Destroy()

The dlg.ImportData() method may also take a function as an optional argument specifying what it should do about malformed rows.  See the example at the bottom of this file. A few common functions are provided in this file (padRow, skipRow, useRow).

There is a more complete example at the bottom of DSV.py.   Just type python DSV.py at the command prompt to see it in action.


Good Luck!

Contact: clifford.wells@attbi.com


SourceForge Logo