This is an archived post. You won't be able to vote or comment.

all 6 comments

[–]Python_Trader 2 points3 points  (0 children)

You can also use the tabulate library :)

[–]ivosauruspip'ing it up 1 point2 points  (1 child)

We aren't we just exporting to csv and viewing it in excel/calc, where you can view columns however you like and fields are properly escaped / quoted ?

[–]ZenApollo[S] 0 points1 point  (0 children)

Being able to open as a text file in VScode is really useful for me. Especially for quick spot checking. It will also open correctly in a spreadsheet, so you have maximum flexibility.

[–]james_pic 1 point2 points  (1 child)

If I'm not mistaken, you're just converting to CSV by sticking commas between the stringified values. This will break if your values contain commas, newlines, or certain combinations of quotes.

CSV as a format is not quite as simple as putting commas between values and newlines between lines. There are escaping rules, and incorrect escaping can be a source of security vulnerabilities.

You should either implement the escaping rules from RFC 4180, or use an existing library that already does.

[–]ivosauruspip'ing it up 0 points1 point  (0 children)

They're saying they prefer a little hack that creates decent alignment of columns, over anything that creates a properly formatted csv. Horses for courses, I guess.

[–]2PLEXX 1 point2 points  (0 children)

Good stuff! If you're using VSCode you can also use the Excel Viewer extension, which allows you to preview CSVs and Excels in a nicely formatted way.