Skip to content

Instantly share code, notes, and snippets.

@olliecheng
Created May 8, 2025 05:59
Show Gist options
  • Save olliecheng/a7fe279f42054433fbd021c70ad21f96 to your computer and use it in GitHub Desktop.
Save olliecheng/a7fe279f42054433fbd021c70ad21f96 to your computer and use it in GitHub Desktop.
Anki: Basic to Cloze card type
import csv
import sys
if len(sys.argv) != 3:
print("Usage: python script.py input.tsv output.tsv")
sys.exit(1)
input_path = sys.argv[1]
output_path = sys.argv[2]
with open(input_path, 'r', encoding='utf-8') as infile, open(output_path, 'w', encoding='utf-8', newline='') as outfile:
reader = csv.reader(infile, delimiter='\t')
writer = csv.writer(outfile, delimiter='\t')
for row in reader:
if row and row[0].startswith('#'):
writer.writerow(row) # keep metadata
else:
if len(row) >= 5:
prompt = row[3]
answer = row[4]
row[3] = f"{prompt}<br /><br />{{{{c1::{answer}}}}}"
row[4] = ""
writer.writerow(row)
@olliecheng
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment