This commit is contained in:
2026-01-23 11:35:09 +08:00
parent 0d17be9a1c
commit 97e47be051
2 changed files with 15 additions and 5 deletions

View File

@@ -234,7 +234,17 @@ def main():
out_cols = ["__cond_file_id"] + out_cols
os.makedirs(os.path.dirname(args.out), exist_ok=True)
with open(args.out, "w", newline="", encoding="utf-8") as f:
out_path = args.out
try:
f = open(out_path, "w", newline="", encoding="utf-8")
except PermissionError:
# If file is locked (e.g. open in Excel), write to a new file
stem = Path(out_path).stem
suffix = Path(out_path).suffix or ".csv"
alt = Path(out_path).with_name(f"{stem}_new{suffix}")
out_path = str(alt)
f = open(out_path, "w", newline="", encoding="utf-8")
with f:
writer = csv.DictWriter(f, fieldnames=out_cols)
writer.writeheader()
@@ -263,7 +273,7 @@ def main():
writer.writerow(row)
row_index += 1
print("exported_csv", args.out)
print("exported_csv", out_path)
print("rows", args.batch_size * args.seq_len)