csv.writer()
csv.writer() is a Python function in the CSV Module category. Returns a writer object for writing rows to a CSV file. The syntax is csv.writer(csvfile, dialect="excel", **fmtparams). Parameters: csvfile — file object for writing. Returns: CSV writer object. A typical example: with open("out.csv", "w", newline="") as f:
w = csv.writer(f)
w.writerow(["Name", "Age"])
w.writerow(["Alice", 30]). A close sibling is csv.reader(), which returns a reader object that iterates over lines in a CSV file. A close sibling is csv.DictReader(), which returns a reader that maps each row to a dict with field names as keys. A close sibling is csv.DictWriter(), which returns a writer that maps dicts to CSV rows using fieldnames. A close sibling is csv.writer.writerow(), which writes a single row to the CSV file (row is a sequence of values). More about this category: CSV file reading and writing — reader, writer, DictReader, DictWriter. For a broader walkthrough, read the CSV Module guide.