diff --git a/assignment_generator.py b/assignment_generator.py index 45b3799..6a46122 100644 --- a/assignment_generator.py +++ b/assignment_generator.py @@ -1,3 +1,4 @@ + import random unique=[] @@ -40,4 +41,4 @@ if(counter>=6): break - print(string) \ No newline at end of file + print(string) diff --git a/delete_record.py b/delete_record.py new file mode 100644 index 0000000..497c4af --- /dev/null +++ b/delete_record.py @@ -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") diff --git a/fileHandling/csv Files/search_record.py b/fileHandling/csv Files/search_record.py new file mode 100644 index 0000000..5ea0b55 --- /dev/null +++ b/fileHandling/csv Files/search_record.py @@ -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....') \ No newline at end of file diff --git a/fileHandling/csv Files/updateCSV.py b/fileHandling/csv Files/updateCSV.py new file mode 100644 index 0000000..c34da99 --- /dev/null +++ b/fileHandling/csv Files/updateCSV.py @@ -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") diff --git a/fileHandling/csv Files/writeCSVFile.py b/fileHandling/csv Files/writeCSVFile.py new file mode 100644 index 0000000..b390e3e --- /dev/null +++ b/fileHandling/csv Files/writeCSVFile.py @@ -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....") diff --git a/fileHandling/csv Files/writeCsvDictWriter.py b/fileHandling/csv Files/writeCsvDictWriter.py new file mode 100644 index 0000000..99cfb7d --- /dev/null +++ b/fileHandling/csv Files/writeCsvDictWriter.py @@ -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....") diff --git a/stock.csv b/stock.csv new file mode 100644 index 0000000..2db755a --- /dev/null +++ b/stock.csv @@ -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 diff --git a/student.csv b/student.csv new file mode 100644 index 0000000..20d4d59 --- /dev/null +++ b/student.csv @@ -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 diff --git a/student.dat b/student.dat index 5feb30d..e69de29 100644 Binary files a/student.dat and b/student.dat differ diff --git a/tempCodeRunnerFile.py b/tempCodeRunnerFile.py index 92b2adf..d27822c 100644 --- a/tempCodeRunnerFile.py +++ b/tempCodeRunnerFile.py @@ -1 +1,2 @@ -target_list \ No newline at end of file +file = open("student.dat","w") +writer = csv.DictWriter(file,fieldnames ="", lineterminator ='\n') \ No newline at end of file