Skip to content
Merged

hola #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added __pycache__/list_adv.cpython-39.pyc
Binary file not shown.
30 changes: 30 additions & 0 deletions file_handling_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
## File pointer ( analogous to a bookmark in a book )

import sys
#sys.path.append("/home/david/hello_world/python/basics")
import os

#import list_adv as f_list ## it has functions to manipulate a list

## infile = open("filename","r") would open the file and put the file
# pointer at the beginning of the file
# ch = infile.read(1) would read 1 byte (one character) from the file
Expand Down Expand Up @@ -49,5 +52,32 @@
dfile.close()


## searching in a binary file

found = False
dfile = open("student_new.dat","rb")
search_for = [] ## these are the roll nos to find for
reply = 'y'
while reply == 'y':
foo = int(input("Enter the roll number to search for :"))
search_for.append(foo)
reply = input("Do you wish to search for more ?(y/n) :")
else :

try:
print("Searching in the file student_new.dat ......")
while True:
data_r = pickle.load(dfile)
if data_r['Roll'] in search_for:
print(data_r)
found = True
except EOFError:
if found == False:
print("no such records found..")

else:
print("search successful")

dfile.close()


1 change: 1 addition & 0 deletions file_handling_4.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
##
File renamed without changes.
Binary file modified student_new.dat
Binary file not shown.