by vortico · 9y ago · 0 comments
With that said, if you are interested in using CSV for encoding and decoding in your own environment, I suggest a new file standard called μTSV.
1. All μTSV files are UTF-8.
2. All values are delimited by "\t", and all lines must end with "\n" (including the last one).
3. If you want to use a "\t" or "\n" character in your value, tough luck---use JSON.
I was not aware of the scorn for the style, I just knew I enjoy reading them.
As opposed to your μTSV may I suggest DSV. The Art of Unix Programming makes a strong case for how it's superior to CSV [1]
1. http://www.catb.org/esr/writings/taoup/html/ch05s02.html#id2...
Processing DSV data (Delimiter-Separated Values) with Python:
https://jugad2.blogspot.in/2016/11/processing-dsv-data-delim...
The example program in the post lets you use either a "-c delimiter_char" or a "-n delimiter_ASCII_code" to specify the delimiter for your DSV data being processed by it.
and
[xtopdf] Publish DSV data (Delimiter-Separated Values) to PDF:
https://jugad2.blogspot.in/2016/12/xtopdf-publish-dsv-data-d...
Bah. How am I wrong when I haven't even claimed DSV to be the best? Just quoting that section in ESR's book does not imply I endorse or agree with it. Logic ...
And if you're using tabs as field delimiters then why do you need quotation marks in the mix?
#!CSV: escape=:\\', quote='"', quotealg='c-like', separator='\t', eof='\n\r', comment='#', encoding='utf-8'
foo bar baz
Such standard (Lets call it mCSV) can be incorporated into existing solutions. Moreover, existing files can be converted from/to a proprietary flavor of CSV to/from metainized CSV.EDIT: The right solution is the simple one. Follow RFC4180 exactly. Reject everything that doesn't match it.
So, yes, follow RFC4180 strictly in your own code, but be able to read CSV files produced by others too. Single line of metainformation can greatly reduce confusion and is easy to throw out, when it is unnecessary.
I think I've said this in another thread, but I think rejecting malformed documents even though you could "figure out what they meant" is the equivalent of not telling people when they have food on their face.
I think the right pattern for something like this is to complain loudly when you are given a malformed document, then say, "If you really want me to parse this malformed document, use --force and I'll try to make some guesses, but really you should just ask for a well-formed document."