pythonwrench.csv module¶
-
pythonwrench.csv.dump_csv(data: Iterable[Mapping[str, Any]] | Mapping[str, Iterable[Any]] | Iterable, file: str | Path | PathLike | TextIOBase | None =
None, /, *, overwrite: bool =True, make_parents: bool =True, to_builtins: bool =False, header: bool | 'auto' ='auto', align_content: bool =False, replace_newline_by: str | None ='\\n', **csv_writer_kwds) str[source]¶ Dump content to CSV format into string and/or file.
- Args:
data: Data to serialize. Can be a list of dicts, dicts of lists or list of lists. file: File path or buffer to write serialized data. overwrite: If True, overwrite target filepath. defaults to True. make_parents: Build intermediate directories to filepath. defaults to True. to_builtins: If True, converts data to builtin equivalent before saving. defaults to False. header: Indicates if CSV must have header. If “auto”, an header is added when a dict of list or list of dicts is passed. defaults to “auto”. align_content: If True, center content at the middle of each row for better visualization. defaults to False. replace_newline_by: Replace newline character to avoid newline in CSV content. defaults to “\n”. **csv_writer_kwds: Others optional arguments passed to CSV writer object.
- Returns:
Dumped content as string.
-
pythonwrench.csv.dumps_csv(data: Iterable[Mapping[str, Any]] | Mapping[str, Iterable[Any]] | Iterable, /, *, to_builtins: bool =
False, header: bool | 'auto' ='auto', align_content: bool =False, replace_newline_by: str | None ='\\n', **csv_writer_kwds) str[source]¶ Dump content to CSV format into string.
- Args:
data: Data to serialize. Can be a list of dicts, dicts of lists or list of lists. overwrite: If True, overwrite target filepath. defaults to True. make_parents: Build intermediate directories to filepath. defaults to True. to_builtins: If True, converts data to builtin equivalent before saving. defaults to False. header: Indicates if CSV must have header. If “auto”, an header is added when a dict of list or list of dicts is passed. defaults to “auto”. align_content: If True, center content at the middle of each row for better visualization. defaults to False. replace_newline_by: Replace newline character to avoid newline in CSV content. defaults to “\n”. **csv_writer_kwds: Others optional arguments passed to CSV writer object.
- Returns:
Dumped content as string.
-
pythonwrench.csv.load_csv(file: str | Path | TextIOBase, /, *, orient: 'list' =
'list', header: bool =True, comment_start: str | None =None, strip_content: bool =False, delimiter: str | None =None, **csv_reader_kwds) list[dict[str, Any]][source]¶ -
pythonwrench.csv.load_csv(file: str | Path | TextIOBase, /, *, orient: 'dict', header: bool =
True, comment_start: str | None =None, strip_content: bool =False, delimiter: str | None =None, **csv_reader_kwds) dict[str, list[Any]] Load content from csv filepath.
- Args:
orient: Orientation of the output value. Can be “list” or “dict”. defaults to “list”. header: Specify if CSV has header column. defaults to True. comment_start: If this string is not None and a line starts with this string, the line will be ignored. defaults to None. delimiter: Value delimiter. defaults to “,”. **csv_reader_kwds: Other optional csv arguments.
- Returns:
The loaded values as dict of lists, list of dicts or list of lists.
-
pythonwrench.csv.loads_csv(content: str, /, *, orient: 'list' =
'list', header: bool =True, comment_start: str | None =None, strip_content: bool =False, delimiter: str | None =',', **csv_reader_kwds) list[dict[str, Any]][source]¶ -
pythonwrench.csv.loads_csv(content: str, /, *, orient: 'dict', header: bool =
True, comment_start: str | None =None, strip_content: bool =False, delimiter: str | None =',', **csv_reader_kwds) dict[str, list[Any]]
-
pythonwrench.csv.read_csv(file: str | Path | TextIOBase, /, *, orient: 'list' | 'dict' =
'list', header: bool =True, comment_start: str | None =None, strip_content: bool =False, delimiter: str | None =',', **csv_reader_kwds) list[dict[str, Any]] | dict[str, list[Any]][source]¶ Load content from csv filepath.
- Args:
orient: Orientation of the output value. Can be “list” or “dict”. defaults to “list”. header: Specify if CSV has header column. defaults to True. comment_start: If this string is not None and a line starts with this string, the line will be ignored. defaults to None. delimiter: Value delimiter. defaults to “,”. **csv_reader_kwds: Other optional csv arguments.
- Returns:
The loaded values as dict of lists, list of dicts or list of lists.
-
pythonwrench.csv.save_csv(data: Iterable[Mapping[str, Any]] | Mapping[str, Iterable[Any]] | Iterable, file: str | Path | PathLike | TextIOBase, /, *, overwrite: bool =
True, make_parents: bool =True, to_builtins: bool =False, header: bool | 'auto' ='auto', align_content: bool =False, replace_newline_by: str | None ='\\n', **csv_writer_kwds) None[source]¶ Save content to CSV format into a file or buffer.
- Args:
data: Data to serialize. Can be a list of dicts, dicts of lists or list of lists. overwrite: If True, overwrite target filepath. defaults to True. make_parents: Build intermediate directories to filepath. defaults to True. to_builtins: If True, converts data to builtin equivalent before saving. defaults to False. header: Indicates if CSV must have header. If “auto”, an header is added when a dict of list or list of dicts is passed. defaults to “auto”. align_content: If True, center content at the middle of each row for better visualization. defaults to False. replace_newline_by: Replace newline character to avoid newline in CSV content. defaults to “\n”. **csv_writer_kwds: Others optional arguments passed to CSV writer object.