From 8361ba50bbf5f76a958344653e2de3b08ac534da Mon Sep 17 00:00:00 2001 From: Forest Gregg Date: Thu, 13 Jun 2024 00:37:13 -0400 Subject: [PATCH] csv --- irs_reader/text_format_utils.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/irs_reader/text_format_utils.py b/irs_reader/text_format_utils.py index 2e395cb..d091e3b 100644 --- a/irs_reader/text_format_utils.py +++ b/irs_reader/text_format_utils.py @@ -48,11 +48,12 @@ def to_csv( ): if not vd: vd = VersionDocumentizer() - stdout = getattr(sys.stdout, "buffer", sys.stdout) + if outfilepath: - stdout = open(outfilepath, "wb") # or 'wb' ? + out_file = open(outfilepath, "w") + else: + out_file = sys.stdout - fieldnames = [] fieldnames = [ "object_id", "form", @@ -65,7 +66,7 @@ def to_csv( "group_name", "group_index", ] - writer = csv.DictWriter(stdout, fieldnames=fieldnames, quoting=csv.QUOTE_MINIMAL) + writer = csv.DictWriter(out_file, fieldnames=fieldnames, quoting=csv.QUOTE_MINIMAL) writer.writeheader() # this fails in python3? results = parsed_filing.get_result()