From 4f5841cbc3ae2c4f1e81faa1d56a07c3581a1a93 Mon Sep 17 00:00:00 2001 From: Jeff Moe Date: Thu, 19 Sep 2024 17:51:39 -0600 Subject: [PATCH] Print CSV header --- hsparse/parse_csv_contacts.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/hsparse/parse_csv_contacts.py b/hsparse/parse_csv_contacts.py index 7995399..a10177b 100644 --- a/hsparse/parse_csv_contacts.py +++ b/hsparse/parse_csv_contacts.py @@ -44,6 +44,13 @@ def parse_args(): action="store_true", ) + parser.add_argument( + "-f", + "--fields", + help="Fields from CSV header", + action="store_true", + ) + args = parser.parse_args() return args @@ -54,6 +61,12 @@ def csv_dump(CSV): for row in contactreader: print(", ".join(row)) +def csv_fields(CSV): + with open(CSV, newline="") as csvfile: + contactreader = csv.reader(csvfile, delimiter=",", quotechar='"') + header = next(csvfile) + print(header) + def main(): args = parse_args() @@ -62,6 +75,8 @@ def main(): if args.dump: csv_dump(CSV) + if args.fields: + csv_fields(CSV) if __name__ == "__main__": main()