diff --git a/samples/load_zarr_stats.py b/samples/load_zarr_stats.py index 5505cee..322bd5e 100644 --- a/samples/load_zarr_stats.py +++ b/samples/load_zarr_stats.py @@ -181,6 +181,7 @@ def load_zarr(zarr_url, average_count=5): args = parser.parse_args() csv_name = args.csv_name +temp_csv = csv_name.replace(".csv", "_temp.csv") output_csv = csv_name.replace(".csv", "_output.csv") column_names = [] @@ -238,7 +239,7 @@ def load_zarr(zarr_url, average_count=5): column_data.append(row) # in case script fails mid-way, we write as we go... - with Path(output_csv).open("a", newline="") as outfile: + with Path(temp_csv).open("a", newline="") as outfile: csvwriter = csv.writer(outfile, delimiter=",", quoting=csv.QUOTE_MINIMAL) csvwriter.writerow(row) @@ -257,8 +258,9 @@ def load_zarr(zarr_url, average_count=5): "fbbiId", ] -with Path(output_csv).open("a", newline="") as csvfile: +# write the final output csv file... +with Path(output_csv).open("w", newline="") as csvfile: csvwriter = csv.writer(csvfile, delimiter=",", quoting=csv.QUOTE_MINIMAL) - # csvwriter.writerow(column_names) - # for row in column_data: - # csvwriter.writerow(row) + csvwriter.writerow(column_names) + for row in column_data: + csvwriter.writerow(row)