Skip to content

Commit e75f0b8

Browse files
authored
Add sep to kv_to_csv
2 parents fbeb7b0 + e332a79 commit e75f0b8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

textractor/entities/page.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ def export_kv_to_csv(
738738
include_kv: bool = True,
739739
include_checkboxes: bool = True,
740740
filepath: str = "Key-Values.csv",
741+
sep: str = ",",
741742
):
742743
"""
743744
Export key-value entities and checkboxes in csv format.
@@ -748,6 +749,8 @@ def export_kv_to_csv(
748749
:type include_checkboxes: bool
749750
:param filepath: Path to where file is to be stored.
750751
:type filepath: str
752+
:param sep: Separator to be used in the csv file.
753+
:type sep: str
751754
"""
752755
keys = []
753756
values = []
@@ -766,9 +769,9 @@ def export_kv_to_csv(
766769
values.append(kv.value.children[0].status.name)
767770

768771
with open(filepath, "w") as f:
769-
f.write(f"Key,Value{os.linesep}")
772+
f.write(f"Key{sep}Value{os.linesep}")
770773
for k, v in zip(keys, values):
771-
f.write(f"{k},{v}{os.linesep}")
774+
f.write(f"{k}{sep}{v}{os.linesep}")
772775

773776
logging.info(
774777
f"csv file stored at location {os.path.join(os.getcwd(), filepath)}"

0 commit comments

Comments
 (0)