Print CSV header
This commit is contained in:
parent
b891fa4823
commit
4f5841cbc3
|
@ -44,6 +44,13 @@ def parse_args():
|
||||||
action="store_true",
|
action="store_true",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
parser.add_argument(
|
||||||
|
"-f",
|
||||||
|
"--fields",
|
||||||
|
help="Fields from CSV header",
|
||||||
|
action="store_true",
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
@ -54,6 +61,12 @@ def csv_dump(CSV):
|
||||||
for row in contactreader:
|
for row in contactreader:
|
||||||
print(", ".join(row))
|
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():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
@ -62,6 +75,8 @@ def main():
|
||||||
if args.dump:
|
if args.dump:
|
||||||
csv_dump(CSV)
|
csv_dump(CSV)
|
||||||
|
|
||||||
|
if args.fields:
|
||||||
|
csv_fields(CSV)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue