mplewis / csvtomd

πŸ“πŸ“Š Convert your CSV files into Markdown tables.
MIT License
655 stars 90 forks source link

Ignore empty lines #3

Closed murphyke closed 7 years ago

murphyke commented 9 years ago

Ignore empty lines but not empty rows.

mplewis commented 9 years ago

It sounds like this might be useful. I found this thread discussing how some programs export empty rows at the bottom of a CSV.

I'm worried about exporting a CSV with empty rows between rows of data. I think this would strip those rows even if they were intentionally added, and I don't want to do that. Can you take a look at that use case?

mplewis commented 7 years ago

Hi @murphyke. Thanks for your submission – sorry it took me so long to get back to you.

I've thought about this and prefer to keep the behavior as-is for empty lines. Based on the Python csv module implementation, If a CSV includes empty lines in the middle or the end, they signify empty rows.

Check out this demo:

Python 3.5.0 (default, Dec 13 2016, 19:02:41)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.38)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> from io import StringIO
>>> c = '''
... 1,2,3
... 4,5,6
...
... 7,8,9
...
... 10,11,12
...
... ,
...
...
... '''
>>> c
'\n1,2,3\n4,5,6\n\n7,8,9\n\n10,11,12\n\n,\n\n\n'
>>> cs = StringIO(c)
>>> r = csv.reader(cs)
>>> pprint(list(r))
[[],
 ['1', '2', '3'],
 ['4', '5', '6'],
 [],
 ['7', '8', '9'],
 [],
 ['10', '11', '12'],
 [],
 ['', ''],
 [],
 []]

I'm comfortable leaving csvtomd mimicking the behavior of Python's csv – it was written by people much smarter than myself. Sorry, but thank you again for your contribution! :shipit: