Skip to content

Commit 65c7683

Browse files
committed
Re-add to_csv method removed by mistake.
1 parent 543ad50 commit 65c7683

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

benedict/dicts/io/io_dict.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,18 @@ def to_base64(self, subformat="json", encoding="utf-8", **kwargs):
208208
def to_cli(self, **kwargs):
209209
raise NotImplementedError
210210

211+
def to_csv(self, key="values", columns=None, columns_row=True, **kwargs):
212+
"""
213+
Encode a list of dicts in the current dict instance in CSV format.
214+
Encoder specific options can be passed using kwargs:
215+
https://docs.python.org/3/library/csv.html
216+
Return the encoded string and optionally save it at 'filepath'.
217+
A ValueError is raised in case of failure.
218+
"""
219+
kwargs["columns"] = columns
220+
kwargs["columns_row"] = columns_row
221+
return self._encode(self.dict()[key], "csv", **kwargs)
222+
211223
def to_html(self, **kwargs):
212224
raise NotImplementedError
213225

0 commit comments

Comments
 (0)