From 8194ccbb38b63e0e29d73bbbdf9b37dd5a0ad529 Mon Sep 17 00:00:00 2001 From: DarkCodeOrg Date: Sat, 14 Aug 2021 19:32:55 +0530 Subject: [PATCH] hola --- __pycache__/list_adv.cpython-39.pyc | Bin 0 -> 2364 bytes file_handling_3.py | 30 ++++++++++++++++++++++++++++ file_handling_4.py | 1 + list-adv.py => list_adv.py | 0 student_new.dat | Bin 152 -> 202 bytes 5 files changed, 31 insertions(+) create mode 100644 __pycache__/list_adv.cpython-39.pyc create mode 100644 file_handling_4.py rename list-adv.py => list_adv.py (100%) diff --git a/__pycache__/list_adv.cpython-39.pyc b/__pycache__/list_adv.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..64382f96621b941b207f3a9c0c3ec68f86220c58 GIT binary patch literal 2364 zcmb_dUvC>l5Z}E!+h^xb2`y@ZD!SqUa#BQEpivY70;M1#p{P)af+ZAPy_@*d^PSmU zJB^h-6~Q~7AbHG3;VaxLPx%Tw@tbiH+kreFai^Qz+1=Zn`OR-;(}jhW!1LQ5chi-I z5Py;~{X|ec$L9(NE!sj$9pthtb*Q6*pdFY{*G%v_kOIBBiO`p%>4uJf5$&38>K59% zp40Pa8+t)6qK)+}{RY~mUea%(ZRy+k4%#_0_gdiZ;HgO78g-TO-OQ=JEe~wkQ?6Sc zIt&>#a7LB;D$kr(TPoE$D-KlVO>a$E(<_G)wQsY+k5#pb6*eU;SyP?dq?n`M)H%Ep zyX{)q@8_mnf1Vb2M=N|d&ZiTzBJ)|AkB=PPpPtH1ap1dT4=rSyI<(>CBhd-*ZR2yR z5MFqxC4iEzgbz-_V{s~_@R0|2Xlo3C00hDA=+T!2jOLw-w8vi4DJC~PQ+SN0ULBPK zb(oS?5*F%HmDH=yd0W-8qCfCei_Fa&nO4=|q$zY&V`Qob+YHWR6%l%8!V(|;dbr*# zduCmy!%VMtO`ex~ho#N+djH6G%VPa`>avbor~UR)J^Y}5R5iXp5U@p)oQxraoR=*b zOFNJL|A)usf5e07U>Fh`z!FQ5u*B=CKAy968Ug!-CA%4cv6!P(jqglv2aYX5nRSdt zZg%V*X1#bUews&+<*}g9{!Aezej~VNayJRtkck0_tmMn<1~i`#g}(vTx5)&uRsh$Q zv`gsSY``XFrbIq%((D^dC{eDNwhn?BNVG4s;wX?XX&u9!bkXN$nc!Gv3z6oBhM(?XKy(AeZmL2}cYfI>G56CQ1(2qI2Jm55!m-AIAmkd#Ylvajd3k3 zet=$s{*~uY6<dV?pLGU#YSkq-cBRlS*2JxRA%zTr-5SgsmA@dnWWmFty`PdZixZ<}-rDEki^>jH1($i$Pq&8^z7I Hf%e|tu}B5R literal 0 HcmV?d00001 diff --git a/file_handling_3.py b/file_handling_3.py index 1808991..c93cacd 100644 --- a/file_handling_3.py +++ b/file_handling_3.py @@ -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 @@ -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() diff --git a/file_handling_4.py b/file_handling_4.py new file mode 100644 index 0000000..32c6af8 --- /dev/null +++ b/file_handling_4.py @@ -0,0 +1 @@ +## \ No newline at end of file diff --git a/list-adv.py b/list_adv.py similarity index 100% rename from list-adv.py rename to list_adv.py diff --git a/student_new.dat b/student_new.dat index eb078dc6cb8d3ce4acc54698d6c44b6c68c9e343..f4fad239acc6e30191fd33ceebec8ba5d4a830a0 100644 GIT binary patch delta 37 tcmbQic#3htjETnL(ix@c`BQpWg7R~6rg&TRu=*wzWfxEJ6=f>b0{{m`4K@G( delta 6 NcmX@bID>J*3;+n?0*wFw