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.
- Pure Python
- Optional wxPython GUI
- Optional heuristics for
determining file format
- Handles embedded quotes,
delimiters and newlines
- Customizable error handling
- Simple to use
- Portable (tested on Linux
- tar zxvf DSV-1.3.6.tgz
(use the version number that you downloaded)
- cd DSV-1.3.6
- python setup.py install
(you'll probably need to be root for this)
- Dunno. I've tested
the code but not the installer. Hopefully DSV-1.3.6.win32.exe works
okay. If not, try installing Linux ;)
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
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)
headers, data = dlg.ImportData() # may also return None
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.