0% found this document useful (0 votes)
7 views

Data File Handling.py Class 12

Uploaded by

sdrive11406
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Data File Handling.py Class 12

Uploaded by

sdrive11406
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

L

6) ’Fle
dAduantiy0
stondd -Oy'
ernsion
memoy
Q4Jo6/24
daiCO
Can E
aa dola a
T
denice
stohed
ttttist coledtone tondtyJatoFt
com be Filos
appent ead
shaned
ponmanent which in
be haroik,t
he
od can daã
wth penmonemt
names sttaglwhich
be
othen
d. ad, çan
Pagc15Date
e chitlen ibe

ainlallE
Can Ne
(
e'hln
Sn dine) Lot a Sh
chanae)
hUnicode.
Ascl
on,
eNe,chanodor text *
*Tebing
secial
Lile,
bs
EOL File
seme each
aultaractorknoon
haracto tetsla.Binay C5
e
deliméter humanCA(to)dat
inono) ino
thi sieadabl.
a
nao-bsi
OL
utransten
EJead tet
as Page Date
hana EQL(end fohm, classm

clon torminatec ie,


Okile
coille
s akes in
L L
Record’102
Eoch data Exteniion Lopehatrn
CSV cmpanistnUin' SoQnd18). humanIhexe Exesion.
Conbinationnln ne
-standi ,no
L03RegroRell
CenisTA
OCOhd
in chanactr
11
[nehe.
xlsx tobiilon Htnal les
Joadable
3 2
toCsV. are
Comna.
Clne
pm TranAfon
Cothpuonbl
sepanatodalue Catiage
ik sto R
TOAdahl.
sprRadsheih tako
ShehacsVAo3,f0t,2
31n inReg'
1ÞI no, moheold dih NQUIA
þlace.
athor
in Page
Aol nùs
ln. That tho
tna

O
le,puthen unicnepythen
uanious'.
SÐnai
epenátien open)Aa
tanchwil andte.yaniabla iirbuilta
le Openinga
TRa. Step 3
K-
n open iCeing
lo
melhods pdaing, Je
l (c:schael 0blegened headingtc
Fle
Nariable i
\chinmaya- hande and
tos | 5cheeltt which
t, uncicns knoon le wing
le as
tot (floname
mode)pen sdatoTsed
') ':r in pen)
Sond
antet
Date
Page8clAssmte
perem nNatable
o c
eldor To
-accen
mhdeTextlila mode.Fiacces
le MmodeFile eq
3* btes e<(ls"ane
Eound¬lh.
bwtlraise
FilaNt ta n
ohenSring hdon 50 Sn
mehtirned le
hint) characor the
'ab' Bìnansl e ("schoel.t","nb
epen whoredãta
pazanaten leoeO bys
pened mut open ohoue
’ prelicing s0me
connedln < mpde exis a make
In slzing
9 Rood
h ne adng meanipecolngse,
Canbe jnle
be<onsut
extonyeipion. extablshed inby
e in Ithas
theatike
qifoldor belere no
it
Jend.chanacte ROadingmode
enalotharuoise beon
oiWslehe
d
the int By the.
ato Wsed
dalault
ble
(

'0+'"atbl
i TevtleBinany
'ab'"a mode 4le

"atbl"
abt' Wtb Jbt
wbt modd

e "
oil Append
dL BWntoandJoadol , ih
w donee beBot Flate=
a Readand dato data 4LBpend
theila
be coniting
Onith \auill the
and beadded. mUt wi!
Jrelainad ading ie Aesciplan.
does ben
exist read and exiAt he
Mt and added exit
SeAding ioinod
ondh theA , 120Page Date

exit, cwriling che<one dessrete


nwsdl to then
can tho. and
new other
daa data a end new ld
Closing-a<iDFle
eadabl-
Rotunr d) (proponbes ("3chieltot)
eq0en Can Once ponlemed cosel
chsed lo
hinto ohother
the lcclhande
osel) - bethe i
) -
Returmns chnied cleet
nohenal ued
o3
to
at
clexed
besleon boedÃan : clee

then a
indicas
cohich valuc.
ohich
Nalvahuerefnd/cats
no
Page Date

*
[:close
unclonnilAstringh nilinrilig (pcael)
print
) ue TueFalseTrite
'schestt
Namo le
`onable
by_ilo
hande ina
writelineAC
te
text
and proes tetie
tuun,an
ugen e
JIQd)
adding. katQutput
Jeadine)
Page
Dote.
.content alAssmate

Ieadlines
hllolnusenlhcoding'
1e-o1
Coting hollo
cdose
closel) Physiolocs)
lwhelto

Pataon

toinouni
doa
3cheeltt Chamistry
LPhuics

Page Date

<i)0pen
Scheoltx.t ischest
aspen
ftky oclose.((over)nt
)aite(C[tuij
Mmihoalun
hao Yotu ("Trbnk
Youtniteh
ot 5chooltxi
o átassale
Thonkheatthy
Yeu Stad Qrúnt co0nk
schost- did
C'halloln hello')
a
tat qreat
Puthon0äput
colndeo geod co
bye oh

Pothon
oupit
atndo
pate
Page.
cAssMAte
Vdoset
Mode. in by Sn onmãtHae
nonThin eninJangej(en)nt olloonq
nao all Th
>l'Hellaln'ern
'slantln'
ba" (sequencel
aniteina
lakandl Tupe mank lirnput("
cnstudent he ask
eontent
sing prognamtnoa int n
linput Entor studenit
lt Dhen Ra
e 8rLMOks" +(" numhen MlGeetem70e 80
12E" a tdisiked Enlor
tet n
( maska c enter
zcadingl1r studext") studeatle
chevth r Page Date

105

adtecend()3nstdotempleybatit ondatrn Ufemponanily,


stoied. Lcosing
letotet
the-danaet
lethoncose0,alto Putabn Output
Tsalan. otces +
ngrba them
add- auipmatcall tho Student COding Aallo
ut" stone. ate
addzOX, oiinge
all leah()à
enlor desqnlionemployee memoyRAM în
aere lshes
T
ilehe
dzes dato
daail, auimataliy
called cn
e)
digk. Date
in Pcge_26dAsSHate

he fience, when
code
cenlact():
da,'
Sel^ phhagnaphO de
s
3
nano Laddrteond
paTagzdphl) Bonphexs
+-dose() chsiwhlcee = tlosel)
t"o)0pen sdolal g
NOC=nm+
hoice 0
to stnlecodo) intltnputinput
int(input guit ""+
Textle "&nl@n
("Pro) "E"+ +ad enton "
phone.tat t"E"+
phone deignaton
stnlsal) safy)
1
no torconlinde deya Page Date

intoi "n4 ) 127


the onil

intogbrindlcaling'
santlax len. CentattO
Roadlnel)
nt(a) readC=
nt(prc) int(6) head2)
pri=eadO (6) Rlahondle.
nead(n and neadlines 0 oa cose)o
fnead (5) nmainput"Enton
younnamo")
pno
nauntytat') nons
int =
(input
heeat ("
6ton

b¡eain phono
no PageDate.
classmate
thom 123
(Lnead
phin()
t print ) Cs
CUt
Sndian.he ujadSnout
dose') nad(s) dose) pnnt
bcase )
(-neàdl2)

Snde Indian.be
benndon
QuTput
121
Page Date

OTE:lo
nemo\e Synlax: Tha gnd
enbtcatt
Gneatork
ennadline ) Hipundtom
netetat heahy
stai pnint Duntprnt Hkhand
nuàdinenl
Snpit into¡en call
etese no
LOadine)Tca ootn
theunton the wil
pnineadine
nt (2)eadinec gplionalpaxamator whjch
occept 1
tmiadion) uncion
nlads
characton L oil a
at in e
st
stausa Output
snestN awnnqwn1at
la
thatIn ead Paga Date
clAsSMAe

gnd. 130
as
byl-and ef n ine
ine Iine a
aihlng
clsel)
ftipen
ngte.-tt )
nint pnint
" (nsplit)
"No-
chsFnoadlinel
e () honltay
Stod
o.
8 pri('end=")
ntnNees.tdt'
, qpen, T)
ecCWene sHEshe S

e He
he
i",c
sitahchlty alqreatdiYedrt tassa Ghoat
Youn00k
did
Page Date

d 131

dtines()
Ibveupuythen Countline)
OAVQEC23M.cOUnt'
ohch onint prünt she da
putho.kt cdose) b=asplit) epenl'neett
printc) daded) ("Fahuendy
"Fraguemcy
itÝn >5
t) ount
phint) (
he
wed eluhes )
)
nle she", 'ya)
andrdisplay
CQuñtthas c)
proqramming" QruRun
pioqnamlng. Date
134PagecAsSMAte
content
5)WAP_To
Ldlosel) nint qasplit0
he
close() noadline
" ond hdhltay'stad atsalase Geato0nk
iclobel)
NO. print
'she' count
6 end= ,
inno.
Neao ")
t
OccUNencOA
extlile
she
is" You iOput
net Gheati0nk
ditaguatYeu
C didOuput
tt. thORed
a Page

qreat 131

ist
lines()
OOAUQE
COunl
ohtchlins 'neteAtt,)
24penl
Hha cAuntin) C23 ca
eha,c)LÁ
Fruquemc
print pnint(3-OAd)
pythomit "Court
a pythemove cdose() pnint() K-cOUnt
iTon>5: ) "rouend
nd b:
in
ns phintt)
she he
()
of ) )
at she",
b=,in',
pthen COurls c2)
ning AruRuyn
puthen
piognanting and
Dat
displas Page_134
cAssMate
Oaput
igs
the
dlines()
oll'nbnies3)nt a)0Pennoett
intt, "ingn
type
healstayt
eadlesin) klndadnea
ehandt (o)
end=

heathyh,"átay
3dlstoåln
aonki
Cqeat
YuTa jolt"stoy
keatayla
dld
a
oneat
Page3S Date

iebb

eadline),
losei
hhe print pntendeDnint buadines AN (ruadines
þyünt0)
(adl2) psnt
cose) prini cdose
LJUadline neD)pen
(Qlo, ('Jt', pyint
noadine
ail, (ndadlne0
() ), a1,al3 OR,
eno) end=
end
it
healiay
tat Stay e content
nsta Qeal. ret
sale dlda
wokn,Ygu QLput
didsa jebid, Page Date
classMate
qneat 36
safel"[tay
ngestt. ieh did
heal a
soth
Jines.
Blaondnk
9
Qadlines)
dhset) L dltsel)
tprints,end=) WAP
ng pnint 52adina) clo(tnd="
e) print t
bao, (i,end ncad
")= comglatu
adhig
le.
and L
Qneat
co0Dk line
aing statsaheal
l Sttaau hialtystay
Üutput bs.line
Date
Page
13T
ald

(9tAPiNcahicha
t clase) print Bn0adlines)
oithJooro"sla
5tant
pnint print
pint (" =tsize
si7e =0
o. ("
NO.G e
"Toial siNtsize'
e
Numben C+=1
Taalsize"e = =
ceiA size ie
e ane
ines t t
in ine) Jen
olJenls)
", ao in ls5lip)
stantng io",
) le
Jing T
excluding tsize
aith in en3)
te
Date
Jten. Page
cIAsSMAte
eading 138
5",c)
Qhich traling
penestt
Seln=
nintphint pnint
in2 wtth print
("No and
"No.("No.("NO. casel) dl¡i
CCtI aton rend)
Cat= af'i1lo:lin
&e
lite) ling Jins a, in
Hhe
stanling
litstanlhg and texila
no
c':
coitce9,
hC"
otch) A",cah
cohich
start
Jinds neles
bt'
139
Page Date

Saln4=opom
(nte.Tt)
(v) m)
Tonitt y-Jead)
oclase)
m=x'roploce (
nead
diq=+ oe: isaalphal)i
C+179
VOW Bigpen02
aeiouAEIOQ':iN Dacos hwer
case

PageL pote
dassute
(10OAP-which
print"No. cose).cdosel)
pnlat pni("A.nt Go
hantng
["N.
cous otter
no: 3amhc'
o'
6-
toanothch
0CCUencoA
sm)
1

'nâle,2.bt. Page41 Date,

dotono():aeh do
maln 'dodtsn.
toaddjelnedthe dodon, siWAPo
onda
ha tt
epomdocen.td',o ht nnotes-tt, ) ath
dhctors
those Name. display
a dn
linput
dont. ange(n):in he Laton oin'aA
=
pp+tpint) He.
ingut"
dh =eEntor
text
otth tluse
tifideot. input On etton
theü
(" eotin
ila thei la
enlen th
Ent o0d,nh"a
-dotos nme 'docton dapanta mong anddisplay
+n's
dapantnent tit. docloy er
dodes Page Date
ngrae") dapaitment elassmate
n 42
Orite
have the lile
sined in

the ile ahich


25A Jastine)Esehdel
3
Sreamin Jmqest) Jastlihe)
cowX. epanagagh JAUDE
etileadmiyion
pnintlLengtth
Lcosel) anoaines
in he
Jine
The ende):nt (a
pri0adine) dastine
Which Jen(}> ma
schoo -t
ait)h e ne =
hy tt Jongest
ine tosnoad
ond
ant have stones dkplay
ling
Takent i,Mok
ines
all
keep the Page Date

all adm ,"Qnd ngest


nale
te

3-closelIL
tt. 4.close) dose) in to
Iine. to heeles
3üng
coide c0Aeiles 3
loni
-noadines
norieve i
lebeok-TtLst
pria]n)t i
Nangeti, 12:0nlaiix
al
in 'stenceTt
the "COME
enal
i,
RCEconerce":
'commeLi
netebogk.textle
Paçe Date.
clAssmate
studentthe
and t
Fon PoitenFile * Ath-faal) (21)
omcline,Conilen
ma called Rondon
501NQ
exiting
ond
Add-nomal ad
) have The
nA Jcase) choe1
okilo. admisaioh"incas4%storeadre
lieand AcOM =0pent'admision.tt Add P'odmission.Lal
a dot mision.tt thel
tt'o
. r namDy
poinoi
nm= cheice te token
in inDt e
epehallons., want ta Dpen
chich = to to
admiNOh al
lo ("enton nampA
: to the updatdde the
0
tile atth
5stem namo" add le
in student
ay
'a Inin he
manages Oa text cas
appld mot Jake ho
stsit udee in
Nled to ankor names howe 45
Page Date

a a Hhe
p ALe
mude
e te
L
a)Abselito a
0sedkseakls)
(10) egt umber
5eoking_Can Bohere seakl)
Ti latseek)
ilahdndle
(ellpet)
seek O hrailemhomthe
6eck
ze) () undlion
RelPiuncing nulnencing-ThË Abscate he
onRelive
siiUNed
aatail
be hi
ukich No.
6oll la)
-f LcÚays
nelonencinq dona.in undisniy sgbk
wil
the pointiat
theispe
ocati. ()
has be to and
X 2 olenenange Chonge
and wed
atg pointen 0docaton
ead om.
oset peillmHhe
haqive,
s s 146Page Date
cdassmute
MOe. ortlen change
and poiteztothe
the te
Date elassmate
Page | Date
Page 143

paramataccep 3 alQ and ia


And
the thselitnerencing by de<atH) bealnndna
the Cuveni
t Jnatutn Cuhnerntpoiton ethe letOad /oxite
pehton. T
ilehandle.toll7/)
Lhen he lite pemed in neadin.,, ths poinon
shuu 5e 0 ines a09
-seek 10,0) when thailo i 'epemed
epenld in mode Hhe
appemd mada,
seck l5.1)
.4ek (+10.2)’ end the kle se 10 ling!
eOpgnt'scheoltt
NOTE: 9+ mwst be reMenmbened that seek
GOnd in binany k lin tet latchestoa 4.seokl3)
pcblem).
ea seck(40,2) Dginta"Cunest notiontotl0)&
10 ines

apnint Guhent petientel))


Output 1 pyTH N ORLO ea

Outpt 2 HON 4 AYTHON wORLO.


nint l-oad 9 ) i e tt . bii
seck (t.o eotJUk
Yoy did a qneat 'schett'
seck 12,0) Stau5alo
nint (L-uot) NOTE 5edk().1and oll ) iall ceunt ln as 2 byte,
while eade) and coriel)ceunt n' as
Stay 5ale
Stag hoalthy
Date
Page
cassmate
Date
Page 50

i in xi =")
on print(i,end Ouput
1 Ram 95
bncadl) eclose) 312 ohani 90
"atnent tabuation)rte
cklo)
hininuod 9) A le predadt. t has alheads beeni creatd oth
Outpt
Hhe' ecods conlaining coda, quanlily pricei tatal amoy
WAUQE sale.()i tor ead the testule and display - d
Gucat o0nk
Giea le taõti ne tpeniag itin append mode ond
Haen agaln displasr all the conterit te lile
5tau heatt
Gpenlpndu tt'ihk
Belneadines)
O8 OAUDE_ ahulaton ) to
print(endotng
Je studeit.The no. C! JocOda to be chaico=ty
shito ohsta =z chocoj==

cotentdisplasy conteit tho lel gts= innut " entr quanhty


pico =input (" enton pnic"
open('hexultst.'u)+) Ham =injt (hentortetal anourt"
I+tam
while choice ==y' chCe ==' +'n'
sn0= int (input ("Entn seridl nunber"
m=int (ingut ent manks" seeklo
Sthlm)+'b naadines)
thoice inputC Pre Yt cottnue elhe pnintli,ende
seeklo
salac
11/07/24 Date classMate
Page 151 Date
Page L52

Fle Pickle module.


d u m p ) " PJoodO
tontt (pickling) ungickling)
to a binary ile
None ditohans) procen
ickling ) he e Cohvenlng the
pntnlbbli This nction i wed to cori object in He Jle
cohlch Gpened in binany imoda"
Sunax
binau le and coner inkt"objet inh pickia dlung lchjca , fiahondla)
madshe néadohleJomat
Mackne Jéadable
eq iniot pickla O0110
bak. openschesl dat.wb)
JOnd Coert m a binau .
pickle dun L. Jr'sch0ol dat
and Canvet the Gnachina noteadabl Lcloset)
'stiuioe into human oadabla ormat.
CohOneven we wok on,- binas Converwen (B) Joad(
For iiadng dato bommk ahinay le e have
taked placo
L
Pickle module will haly int y converon
objedtpichle load (ilahandl:)
(al dunpt) ond
(6) Lod
'opemi schoo dat, nb)
Nidyalnya schoe! 01000001 pickla- load ( | ) b
5,'a, "b'
binas) Lclose)
unglcking .

NOTE: Joad() ads only d chiect eohich a, dumped


sdhool dát
the binan le
DaTe
Page155 * Code - cpi252 alassMate
Date
Page

picte-dtomo
6.6c. Ae 22, Hello usen, ,2,3, (40,90) seak(o) Hello ue
stat coding.
pichle. Auny la pickk Joad () in
picklo. duy (b, pnintx)
lab
hickle- duh le., OlLAP to ask uer o unben
seok (o) den0idat student Fon each
student ak themto enlor ngnt, clam,percenlog.51
pront) hee ddail in te e school dat Them pnint e
dto in un broper o7mdt Gn outnt schesm
al dsplay enoa4 studery qaling, mohe than 51- monk
Jngma 1LU:
Lose)
4,231 (c) dotaile thee studemi whole namO, 6tart
30,90)
=0pen ('deo. dat 'ib)

open'schonl-dat','wbt)ic
dhsebl zit (ingut ("Enton nunken c studnl )
EOF: End 10.20)
*impot pickla EOF eNOn: Ran aut o
d-int (iut ("enter cas")
p07= int (iut ("Entn
b="Helle oh =Onm,d.pon
in Lpckla dung(.0
oseck (o)ß
O1013 o1100
+
pnint ("Reeond all studenta")
pckle -dung a, ) doma.dat'
classte
Page
Date.
Page 156

impent pickle
dok phonapdato ():

ohileO
print ("atails e! studest, Qhele name.
prnt ("modal io Cotnpany nane "eld
ane", tlo plhtre nfpric "nelo pric
onint"Stdent in cla
More thah 951
Lcosel) phuntitol,i], il2 ,np
Lclose)
Nanjeu smantphone. The company hasi decided ti U phondupdataD
trieve eah hecond nen e lile and dspla 3A ibnanian "hasYCneatid a birars e libnany dat'
modem cld pnices and now pr~ceA on 5cIRon stoing beek title & cas WAUQE oskach
Sgln ioyot gickl kte atd diplas only hese beak 1tly which balan to clon.
en hsae drt 'nbt)
do seatch():i
(bnag-dat',sb)
ingeit pickle

pickle' load ) print (ilo?


oni inx
Q= 1-]
Lclose)h
seanch
i-1]= at{0.2*d)
phontupdatC
OR,
Date
Page 15
i
Saln impent picklo
cheatod epen (stident dat,'b
ke nam,(las, el n.on
=0 -. ( ! i
tocd el otudert Q- Input "enton name. to be seached"
MOnA sttent hauc jched the same clas. while Tue :
ent he inlematim in te binany ile 'stud
content
4 erenlstident- dat"abt" break
1=1 print CRecod ngt availahla")
pse:
nèn =ingut "'erton námo" pnint ("Recond kxtht ")
d= tnaut ("ento clas")

Updáting in ig Binay il
dslcezinfut ("Ent y" to cenrun elke prOA) "Q 6 A la 'student. dat alneads ceattd containing
to t"):
pickla.duingbrE.
secklo)
and then updato the clam
pen the hel no. qlven by the wer
the student as
takes tue prevtous daã ingot pickle
Cpen(" sludernt dat" "nbt")
cdosel) X= pickle. Joad ()
seanhing in a Bioany e data yinnettd. no haint (input ("erto
aund= 0
hell no. to be seanched")

student Gnd search whothen the


availabls in the e s net.
Aame
laund =
braak
clAssMAte
Date
Page
J59 Date
Page 160

inpertpickla
secklo) epen lstudont . dat'. ribt)
y='pickle. load2)
:seck lo) print (1ontent "e the liai"
5eck (o)
pant"e cotent el the le ,
cese) Ay Run
CFAom'.12.1o], 'Hohan',0,11| A3ss, 12,271
TCRam', 12. i0], rHohor, 12, 11||i1 elsei .

Aeiling in a. Binan File. UO ickle dumpla.)T


OA o student.da elset
aheady cheátod ahene. QsliL Paint ("Not eund
Haee student condnskh ila tohich ho
4Gen 'student:dat', 'nb+) )
cosel)
pickle: load (p)

Y.NAMOVe (i) Excaptioniandtng


seaklo the number e Oreconds n the ie . Under [uch
ickle- dungl,) Cincumstonce_accening all the' necoad, appropratol,
seck (o) non the Jile will be'ia dillicut tesh
ue ian nnit docy to acen oll
prlrt ("Nes chtent
osel) Jord s° being accened, the system wll promat
OR, EOFEwN
L
’Thotru
excapt ahon diteated Try-excegt 30.
ock':accese Sn
htndling
cepltn blsignaloend
EOE eadh
blek the
E0FEULSN! L
ty by block Ethsutem
Ucones itotion'
block tuy cComes
lot
ine block. Thies
esepetencDs Us en
aclbn. to
sheon.neconda Io
qel
Lerceht i ut'a
eher no
accehed
monages hecond 16
Page Date
then SMAe

priteoinnerA)Sedenl
Thé 8
pricasinnozA
oiWAUE
th cdaw' aynloy
eapkie3 excapt
"pnico.dat'conain,
clask necord lo
Nohle ue
0 and
Tuei
(ohile
0penprtcedat'
"nb) en iei:
T
ond Diank
sieJ
Jank

) ohohae piceall
dibolau impontpickl
prunt"EONn the pen
5coJed winnes
all.
seetcontxling
name pintbstudentdat,
sthe Date
Page162clAssMAte
Jronk
homes
cda
1.d b')
12
Date dAssate
Page163 Date
Page T64

wTLONgly as 541- Change hinlhor mank, to 649.


chsel) A
ae neo student has johed the Bchesl Add his hen
pizeuinners)
centained Nanme - 5unadh fnakash, tata maikst 9, kolng.-45.
49dt w osurns thad the dato th 58l9 impot pickle
tiuc eQen TOlt- dat' b)
COndiims¥ndn tu block i
pzint(
seklo)
9 la"5at dat' conains a
J the 3ot alene colth thein cagttala ohase in x:

5lninpat pickle

Lseoklo
t railollongt initaeioü AFIOU
print() sek'o
he pickle-lo ad()
prùnt ("Nec Cortent
(0)
Vholt dat', 'bt"t
epckle-load
ollaoing student penlen
a)Àstudenit ottaJl no 8 had Jelt the sche
studert whee

You might also like