Skip to content

Commit a45df43

Browse files
Handling of CSV files using csv module,writting employee data into csv file using writer(),writerow().
1 parent 2ac8dd6 commit a45df43

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

FileHandling8.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#Handling csv files using csv module
2+
#Writting employee data into csv file
3+
4+
import csv
5+
with open('emp.csv','w',newline='') as f:
6+
w=csv.writer(f) #returns the writer object pointing to f
7+
w.writerow(['ENO','ENAME','ESAL','EADDR'])
8+
n=int(input("Enter the number of Employees:"))
9+
for i in range(n):
10+
eno=int(input("Enter Employee Number:"))
11+
ename=input("Enter Employee Name:")
12+
esal=float(input("Enter Employee Salary:"))
13+
eaddr=input("Enter Employee Address:")
14+
w.writerow([eno,ename,esal,eaddr])
15+
print("Total Employee Data inserted into csv file:",f.name)
16+

emp.csv

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ENO,ENAME,ESAL,EADDR
2+
100,Rishabh,50000.0,Pune
3+
101,Vishal,52000.0,Pune
4+
102,Vaibhav,100000.0,Hyderabad
5+
103,Ashu,40000.0,Mumbai

0 commit comments

Comments
 (0)