Skip to content

Commit

Permalink
csv files programs added
Browse files Browse the repository at this point in the history
  • Loading branch information
rakeshlinux committed May 17, 2020
1 parent 25bb981 commit 9344012
Show file tree
Hide file tree
Showing 10 changed files with 119 additions and 2 deletions.
3 changes: 2 additions & 1 deletion assignment_generator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import random

unique=[]
Expand Down Expand Up @@ -40,4 +41,4 @@
if(counter>=6):
break

print(string)
print(string)
29 changes: 29 additions & 0 deletions delete_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import csv
name = input('Name to delete :')
# this is comment
# hello rakesh this is comment
""" this is multi line commnet"""

records=[]
found =0
file = open("student.csv","r")
reader = csv.DictReader(file)
for record in reader:
record = dict(record)
if(record['name']!=name):
records.append(dict(record))
else:
found =1
file.close()
# Remove the old file and create a new csv file
headers=['rollno','name','stream','fees']
file = open("student.csv","w")
writer = csv.DictWriter(file,fieldnames =headers, lineterminator ='\n')
writer.writeheader()
writer.writerows(records)
file.close()

if(found==0):
print(name, " does not exists")
else:
print(name," deleted successfully")
15 changes: 15 additions & 0 deletions fileHandling/csv Files/search_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import csv
name = input('Name to Search :')

file = open('student.csv','r')
reader = csv.DictReader(file)
found =0
for x in reader:
x = dict(x)
if(x['name']==name):
print(name,' found in CSV file..')
found =1
file.close()

if(found == 0):
print(name, ' not found....')
31 changes: 31 additions & 0 deletions fileHandling/csv Files/updateCSV.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# program to update a record in csv file
import csv
name = input('Name to Update :')
records = []
found = 0
file = open("student.csv", "r")
reader = csv.DictReader(file)
for record in reader:
record = dict(record)
if(record['name'] == name):
record = dict(record)
record['name'] =input('New Name:')
records.append(record)
found=1
else:
records.append(dict(record))
file.close()

# Remove the old file and create a new csv file
pr
headers = ['rollno', 'name', 'stream', 'fees']
file = open("student.csv", "w")
writer = csv.DictWriter(file, fieldnames=headers, lineterminator='\n')
writer.writeheader()
writer.writerows(records)
file.close()

if(found == 0):
print(name, " does not exists")
else:
print(name, " updated successfully")
15 changes: 15 additions & 0 deletions fileHandling/csv Files/writeCSVFile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import csv
records =[
["ID", "name", "Price", "Qty"],
["102","LG Monitor","6500","20"],
["103","KeyBoard","1350","156"],
["105","Hp Mouse","650","120"],
["106","Speaker","1670","136"]
]

f = open("stock.csv","w")
csvwriter = csv.writer(f,lineterminator="\n")
# csvwriter.writerow(header)
csvwriter.writerows(records)
f.close()
print("Check your file now....")
15 changes: 15 additions & 0 deletions fileHandling/csv Files/writeCsvDictWriter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import csv
headers =['rollno','name','stream','fees']
records = [
{'fees': 2356,'rollno': 12, 'name': 'surendra', 'stream': 'Humanities', },
{'rollno': 13, 'stream': 'Humanities', 'fees': 2356,'name': 'Ashok', },
{'rollno':15,'name':'Nipun','stream':'Humanities','fees':2356},
{'rollno': 22, 'name': 'Ayush Negi', 'fees': 2356,'stream': 'Science', },
]

f = open("student.csv", "w")
writer = csv.DictWriter(f, fieldnames = headers, lineterminator='\n')
writer.writeheader()
writer.writerows(records)
f.close()
print("Check your file now....")
5 changes: 5 additions & 0 deletions stock.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ID,name,Price,Qty
102,LG Monitor,6500,20
103,KeyBoard,1350,156
105,Hp Mouse,650,120
106,Speaker,1670,136
5 changes: 5 additions & 0 deletions student.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
rollno,name,stream,fees
12,surendra,Humanities,2356
13,Ashok Goyal,Humanities,2356
15,Nipun,Humanities,2356
22,Ayush Negi,Science,2356
Binary file modified student.dat
Binary file not shown.
3 changes: 2 additions & 1 deletion tempCodeRunnerFile.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
target_list
file = open("student.dat","w")
writer = csv.DictWriter(file,fieldnames ="", lineterminator ='\n')

0 comments on commit 9344012

Please sign in to comment.