# -*- coding: utf-8 -*- """ Created on Thu Aug 14 13:21:08 2025 @author: Kirti Hora """ import csv def createcsv(): filename = "emp.csv" with open(filename, "w", newline="") as csv_fobj: wtr_obj = csv.writer(csv_fobj) wtr_obj.writerow(["Empno", "Name", "Basic Salary", "Allowance", "Deduction", "Net Salary"]) while True: eno = input("Enter employee no: ") name = input("Enter name: ") bs = float(input("Enter basic salary: ")) allowance = 2000 dedn = bs * 0.05 net = bs + allowance - dedn wtr_obj.writerow([eno, name, bs, allowance, dedn, net]) ...
CSV FILE (COMMA SEPERATED VALUE) Writing data to a CSV file involves the following steps: Import the csv module Open the CSV file in write mode ( "w" ) using open() Create the writer object Write the data into the file using the writer object Close the file using close() writerow() Method This method is used to write a single row to a CSV file. It takes a sequence (list or tuple) as its parameter, and writes the items as a comma-separated line in the file. You do not need to add a newline character (\n) — it automatically places the end-of-line marker. EXAMPLE 1: import csv # Importing the csv module # CSV file opened using relative path csv_fobj = open("emp.csv", "w") # Writer object created wtr_obj = csv.writer(csv_fobj) # Record with field heading is written wtr_obj.writerow(["Empno", "Name", "Salary"]) # Records with data are written wtr_obj.writerow([1, "Akash...