-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9344012
commit 3cf8dd9
Showing
6 changed files
with
83 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import csv | ||
|
||
rollno= int(input('Roll No :')) | ||
name = input('Name :') | ||
stream = input('Stream :') | ||
fees = int(input('Fees :')) | ||
|
||
records = [rollno,name,stream,fees] | ||
|
||
f = open("student.csv", "a") | ||
csvwriter = csv.writer(f, lineterminator='\n') | ||
# csvwriter.writerow(header) | ||
csvwriter.writerow(records) | ||
f.close() | ||
print("Record added ...") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# program to update a record in csv file | ||
import csv | ||
name = input('Name to Delete :') | ||
records = [] | ||
found = 0 | ||
file = open("student.csv", "r") | ||
reader = csv.reader(file) | ||
for record in reader: | ||
if(record[1]!= name): | ||
records.append(record) | ||
found = 1 | ||
|
||
file.close() | ||
|
||
# Remove the old file and create a new csv file | ||
file = open("student.csv", "w") | ||
writer = csv.writer(file,lineterminator='\n') | ||
writer.writerows(records) | ||
file.close() | ||
|
||
if(found == 0): | ||
print(name, " does not exists") | ||
else: | ||
print(name, " deleted successfully") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import csv | ||
name = input('Name to Search :') | ||
|
||
file = open('student.csv', 'r') | ||
reader =csv.reader(file) | ||
found = 0 | ||
for x in reader: | ||
if(x[1] == name): | ||
print(name, ' found in CSV file..') | ||
found = 1 | ||
file.close() | ||
|
||
if(found == 0): | ||
print(name, ' not found....') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1 @@ | ||
import csv | ||
f = open(r"C:\Users\rakesh\Desktop\student.csv", "r") | ||
data = csv.DictReader(f) | ||
for record in data: | ||
print(record) | ||
f.close() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# 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.reader(file) | ||
for record in reader: | ||
if(record[1] == name): | ||
record[1] = input('New Name:') | ||
records.append(record) | ||
found = 1 | ||
else: | ||
records.append(record) | ||
file.close() | ||
|
||
# Remove the old file and create a new csv file | ||
headers = ['rollno', 'name', 'stream', 'fees'] | ||
file = open("student.csv", "w") | ||
writer = csv.writer(file, lineterminator='\n') | ||
writer.writerow(headers) | ||
writer.writerows(records) | ||
file.close() | ||
|
||
if(found == 0): | ||
print(name, " does not exists") | ||
else: | ||
print(name, " updated successfully") |