From 50358fa82d3139356768784f430d25e474f6e064 Mon Sep 17 00:00:00 2001
From: Matthias Diener <mdiener@illinois.edu>
Date: Mon, 24 Aug 2020 23:23:08 -0500
Subject: [PATCH] Table: add csv output

---
 pytools/__init__.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/pytools/__init__.py b/pytools/__init__.py
index 394bb87..90103e0 100644
--- a/pytools/__init__.py
+++ b/pytools/__init__.py
@@ -1561,6 +1561,18 @@ class Table:
 
         return "\n".join(lines)
 
+    def csv(self):
+        """Returns a string containing a CSV representation of the table."""
+        import csv
+        import io
+
+        output = io.StringIO()
+        writer = csv.writer(output)
+        writer.writerows(self.rows)
+
+        return output.getvalue().rstrip('\n')
+
+
     def latex(self, skip_lines=0, hline_after=None):
         if hline_after is None:
             hline_after = []
-- 
GitLab