Download file handling computer science class 12 cbse and more Study notes Computer science in PDF only on Docsity!
COMPUTER SCIENCE HANDWRITTEN NOTES GUWAS'S 1:2 GBS EF ACADEMIC YEAR: 2025-2026 classmate O Dale aN ‘ Page _ aaa A file is a collection of data stoned ina storage ___ device It Contains text. images, videos etC. Files he essential fox Atoning “data x DATA FILES : files that ave data. Rieti to a specific app licadten. me < Data files can be stoned in. two Ways — 1) Text files il) Binany tiles Fd Text Eves’: [t stoves infoamation im the form_ot o._stneam of ASCIT on: unicode. ‘cravattas tach tine of a text ic terminated with a special chan Oe known od FOL (tnd ot tine chanactor i f nt LREGUIAR TEXT PILES 3 these: ahiois the Faye in_ the same. foam as typed These tiles have O .le_extension a tot. — 1) DE UMITED TEXT ELLE: to me Oe values jee 0. v | tab ox a. uomma_sepanated. at ker each value e)—Used 10 sb para. values ctored T lesv (comma Se panated value)- comma fe used tn separate the values stp ted ss al ie. vane aa) | " - [ae lose function bxeaks the ink OP tec im | object. ond the pile on the disk. Aptex ST RO aerate rep > onthak. __|-—_— __*_ WORKING WITH “TEXT eA ane ° tJ __ 1 Reading trom texttiles — 1 | READ()® retums read bytes in foum of sting. 2- |READLINE()% reads a line of [nput, Retums. the read bytes in theitonm ofa staing 3-READLINES() 2 reads a) the Mines and return them ina fet *_|APPENIDIN( ASFIIE * O tite opened | in! append ible scofaing StS: previous data. waite. ‘ : cy eam Waiting. onto tert files - i i 1: |WRITE(D* {t onites the content in the +fle ——2: |WRITELINES( 92 writes. the content of Qi0 strings @ = _ ——s in dist. The_Flusht function sth foces. oi be crtting of data. on dise s#tyi — pring in on er eae Removing White Spaces otter Reading #romfiles— __ Stxip(2+ removes the given chanactex $xom both ends 2- I rstnip() removes the afven chaxactex prom trailing end Loughe end) ze [stuip (> * removes the given ehavactey #x0m_ Leadin end (Yeprend ) Ww Stanificance of File Pointe: in- fie Hand din img = Jd U Evexy. file maintains a tile ainty urfaich. fetta, the cunrnent position inthe pile grt. wxiting Ox xoading, wo Lake place File modes Opening panition 4 nb, 1+, xbt wtb beginming ob the tile WwWb,wt,wht+,wtb beginning ofthe file __ O,ob,a+, 0b+, atb Reading ¢xom oO. Binany File — once_you have writhn onto a file using. pickle module's dum pc) you need to Xead fxom the tile using pickle load You. can handle this by = 1) Use tty and &xce} 9 slatemonts tog shor 5 con _hondde stuuntime ercceptions —__ fi) Using. With stabement— the with statement will also close Phe tile outomaticaliy after with block ig OVE * Seaxching ino file — SEQUENTIAL SEARCH? you %ead the ecards pxomm_o. file ohe b ACCESSING AND MANIPUOLATIN (Gr LOCATON ‘OF FILE! POINTER — The two file pointex location functions aie | te1. 0) and “Seek The tel) () tunction® retums the: winwemt position of gile pointer Inthe pile The_Seekt) funcHon + Chhanges_the position of the file. - Pointer -by_plasing, Me Mle — on} e4eed c, qv Open file sae pickle. p pickting ‘trxox > xaised ushen an un pickable pbjeck is cri ee eae wssiiting, pickie.unpichting tuto? nofsed during Q aa F ae paged eon unpickiina ofan obfect: ~ T ov oC WORKING WITH CSV FINES — csv files one delimited piles phat store fabullox dato In(sV_, Values axe separated with Comma Cod ____ | & ye vate) ee SS erie | eee nee teeter asia os picasa a re ae Fy caeLasenae —s i . _woutexous (> 2 to nites _muttipbe | Aeon lh rows of data mo We the uxitex pbjeck "x READING IN CSV FILES’ — : es | i ites f Aoading of a._csv file's data ie stemoving its dele o tation Stoning. imto python iterahle: amd Heading 20m this. j cave Keader C) — returns a neadex obfeck sahich toads data txom csv tile. imt it \ i j o 1 Le o d cata ss ely, SMe vite =~ — a Bate - = A > Page le 1PORTA NT QUESTIONS — J eae a 1: hai is the. difference _betsoeen a text. 4 — File omd oa _binaxy file 2 a | Ans. | A bext_file stores mformation in_ ASCII _——___aosountinale) “chasbochew esi wes ae Fach sine. ts _texominated with { Chawackex called EOL (tnd of Lime) | chaxackex | lA binany tile Stoxes infox mation In_the Ee ob a steam of bytes \ In binany thene is no -delimtter tox Lines ‘what is the difference betmeen oad (> land sxoad tines ¢> function and seadline (> D- Ans. The readt) reads from a Mle fo x2ad mode, ~ond. stipes its contents in a styvina type pte readlines() function , xeads from a file in wwad mode and sutuina a dist of ald dines in the file ‘the xeadJinec) seeads pom a_i imode ond xetuns the next tne in the fle | _statng [} thexe oxe no mone lines _—— jo aioe ——————SSSS==a | = What ts file_hand ting, ? why is th needed? File perm he te s-aaitay- | tetufeving, and modit ddtatin. ii sami ° dG Oo $i poxmanentl So thar It can be accessed even aster. the program is closed . -| What fs the purpose of geek) and Peyecy 2 Fins. | Seebt is used to move the sile pointer to pa specteled pasttion tn the ile. Tec) setuma the cunsxent position of the +fle Pointer Eploin ditferent tile Modes 3 Read (x) * open» a file Wyite (wi? Crates a neu) tile OX over uniter an existing one, of j Append(a): adds data ab the endoftthe pile 7