-
Notifications
You must be signed in to change notification settings - Fork 12.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: slowy07 <[email protected]>
- Loading branch information
Showing
388 changed files
with
8,353 additions
and
6,251 deletions.
There are no files selected for viewing
18 changes: 10 additions & 8 deletions
18
1 File handle/File handle binary/Deleting record in a binary file.py
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,22 +1,24 @@ | ||
import pickle | ||
|
||
|
||
def Bdelete(): | ||
# Opening a file & loading it | ||
F= open("studrec.dat","rb") | ||
F = open("studrec.dat", "rb") | ||
stud = pickle.load(F) | ||
F.close() | ||
|
||
print(stud) | ||
|
||
# Deleting the Roll no. entered by user | ||
rno= int(input("Enter the Roll no. to be deleted: ")) | ||
F= open("studrec.dat","wb") | ||
rec= [] | ||
rno = int(input("Enter the Roll no. to be deleted: ")) | ||
F = open("studrec.dat", "wb") | ||
rec = [] | ||
for i in stud: | ||
if i[0] == rno: | ||
continue | ||
rec.append(i) | ||
pickle.dump(rec,F) | ||
This comment has been minimized.
Sorry, something went wrong. |
||
pickle.dump(rec, F) | ||
F.close() | ||
|
||
|
||
|
||
Bdelete() |
24 changes: 13 additions & 11 deletions
24
1 File handle/File handle binary/File handle binary read (record in non list form).py
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,23 +1,25 @@ | ||
import pickle | ||
|
||
|
||
def binaryread(): | ||
B=open("studrec.dat","rb") | ||
stud=pickle.load(B) | ||
B = open("studrec.dat", "rb") | ||
stud = pickle.load(B) | ||
print(stud) | ||
|
||
# prints the whole record in nested list format | ||
print("contents of binary file") | ||
|
||
for ch in stud: | ||
print(ch) #prints one of the chosen rec in list | ||
Rno=ch[0] | ||
Rname=ch[1] #due to unpacking the val not printed in list format | ||
Rmark=ch[2] | ||
|
||
print(Rno, Rname,Rmark, end="\t") | ||
|
||
print(ch) # prints one of the chosen rec in list | ||
|
||
Rno = ch[0] | ||
Rname = ch[1] # due to unpacking the val not printed in list format | ||
Rmark = ch[2] | ||
|
||
print(Rno, Rname, Rmark, end="\t") | ||
|
||
B.close | ||
|
||
|
||
binaryread() |
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,31 +1,33 @@ | ||
#Updating records in a binary file | ||
# Updating records in a binary file | ||
|
||
import pickle | ||
|
||
|
||
def update(): | ||
F=open("class.dat",'rb+') | ||
S=pickle.load(F) | ||
found=0 | ||
rno=int(input("enter the roll number you want to update")) | ||
F = open("class.dat", "rb+") | ||
S = pickle.load(F) | ||
found = 0 | ||
rno = int(input("enter the roll number you want to update")) | ||
for i in S: | ||
if rno==i[0]: | ||
print("the currrent name is",i[1]) | ||
i[1]=input("enter the new name") | ||
found=1 | ||
if rno == i[0]: | ||
print("the currrent name is", i[1]) | ||
i[1] = input("enter the new name") | ||
found = 1 | ||
break | ||
|
||
if found==0: | ||
if found == 0: | ||
print("Record not found") | ||
|
||
else: | ||
F.seek(0) | ||
pickle.dump(S,F) | ||
F.seek(0) | ||
pickle.dump(S, F) | ||
|
||
F.close() | ||
|
||
F.close() | ||
|
||
update() | ||
|
||
F=open("class.dat","rb") | ||
val=pickle.load(F) | ||
F = open("class.dat", "rb") | ||
val = pickle.load(F) | ||
print(val) | ||
F.close() |
31 changes: 16 additions & 15 deletions
31
1 File handle/File handle binary/Update a binary file2.py
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,30 +1,31 @@ | ||
#updating records in a bnary file | ||
# updating records in a bnary file | ||
|
||
import pickle | ||
|
||
|
||
def update(): | ||
F=open("studrec.dat","rb+") | ||
value=pickle.load(F) | ||
found=0 | ||
roll=int(input("Enter the roll number of the record")) | ||
F = open("studrec.dat", "rb+") | ||
value = pickle.load(F) | ||
found = 0 | ||
roll = int(input("Enter the roll number of the record")) | ||
for i in value: | ||
if roll==i[0]: | ||
if roll == i[0]: | ||
print("current name", i[1]) | ||
print("current marks", i[2]) | ||
i[1]=input("Enter the new name") | ||
i[2]=int(input("Enter the new marks")) | ||
found=1 | ||
i[1] = input("Enter the new name") | ||
i[2] = int(input("Enter the new marks")) | ||
found = 1 | ||
|
||
if found==0: | ||
if found == 0: | ||
print("Record not found") | ||
|
||
else: | ||
pickle.dump(value,F) | ||
pickle.dump(value, F) | ||
F.seek(0) | ||
newval=pickle.load(F) | ||
newval = pickle.load(F) | ||
print(newval) | ||
|
||
F.close() | ||
update() | ||
|
||
|
||
|
||
update() |
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
20 changes: 11 additions & 9 deletions
20
1 File handle/File handle binary/search record in binary file.py
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,22 +1,24 @@ | ||
#binary file to search a given record | ||
# binary file to search a given record | ||
|
||
import pickle | ||
|
||
|
||
def binary_search(): | ||
F=open("studrec.dat",'rb') | ||
F = open("studrec.dat", "rb") | ||
# your file path will be different | ||
value=pickle.load(F) | ||
search=0 | ||
rno=int(input("Enter the roll number of the student")) | ||
value = pickle.load(F) | ||
search = 0 | ||
rno = int(input("Enter the roll number of the student")) | ||
|
||
for i in value: | ||
if i[0]== rno: | ||
if i[0] == rno: | ||
print("Record found successfully") | ||
print(i) | ||
search=1 | ||
search = 1 | ||
|
||
if search==0: | ||
if search == 0: | ||
print("Sorry! record not found") | ||
F.close() | ||
|
||
binary_search() | ||
|
||
binary_search() |
14 changes: 8 additions & 6 deletions
14
1 File handle/File handle text/file handle 12 length of line in text file.py
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,10 +1,12 @@ | ||
def longlines(): | ||
F=open("story.txt","r") | ||
line=F.readlines() | ||
F = open("story.txt", "r") | ||
line = F.readlines() | ||
|
||
for i in line: | ||
if len(i)<50: | ||
print(i,end=" ") | ||
if len(i) < 50: | ||
print(i, end=" ") | ||
|
||
F.close() | ||
longlines() | ||
|
||
|
||
longlines() |
21 changes: 13 additions & 8 deletions
21
1 File handle/File handle text/input,output and error streams.py
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,15 +1,20 @@ | ||
#practicing with streams | ||
# practicing with streams | ||
import sys | ||
|
||
sys.stdout.write("Enter the name of the file") | ||
file=sys.stdin.readline() | ||
file = sys.stdin.readline() | ||
|
||
F = open(file.strip(), "r") | ||
|
||
F=open(file.strip(),"r") | ||
|
||
while True: | ||
ch=F.readlines() | ||
for i in ch(): #ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words | ||
print(i,end="") | ||
ch = F.readlines() | ||
for ( | ||
i | ||
) in ( | ||
ch() | ||
): # ch is the whole file,for i in ch gives lines, for j in i gives letters,for j in i.split gives words | ||
print(i, end="") | ||
else: | ||
sys.stderr.write("End of file reached") | ||
break | ||
F.close() | ||
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
Oops, something went wrong.
thanks