MCPcopy
hub / github.com/catherinedevlin/ipython-sql / csv

Method csv

src/sql/run.py:238–259  ·  view source on GitHub ↗

Generate results in comma-separated form. Write to ``filename`` if given. Any other parameters will be passed on to csv.writer.

(self, filename=None, **format_params)

Source from the content-addressed store, hash-verified

236 return plot
237
238 def csv(self, filename=None, **format_params):
239 """Generate results in comma-separated form. Write to ``filename`` if given.
240 Any other parameters will be passed on to csv.writer."""
241 if not self.pretty:
242 return None # no results
243 if filename:
244 encoding = format_params.get('encoding', 'utf-8')
245 if six.PY2:
246 outfile = open(filename, 'wb')
247 else:
248 outfile = open(filename, 'w', newline='', encoding=encoding)
249 else:
250 outfile = six.StringIO()
251 writer = UnicodeWriter(outfile, **format_params)
252 writer.writerow(self.field_names)
253 for row in self:
254 writer.writerow(row)
255 if filename:
256 outfile.close()
257 return CsvResultDescriptor(filename)
258 else:
259 return outfile.getvalue()
260
261
262def interpret_rowcount(rowcount):

Callers

nothing calls this directly

Calls 4

writerowMethod · 0.95
UnicodeWriterClass · 0.85
CsvResultDescriptorClass · 0.85
getMethod · 0.80

Tested by

no test coverage detected