Professional Documents
Culture Documents
it
ata handling
F.wt RAadlnusO -
F. elose)
I tudy empilu.\n"). te riad allanw o m u
l Lstants readEiug e m h e kiu
stauts eadnna e ti uLnsO
lut ead- ket ) :
F CaMy. tet ")
up to t eud
uu F . rdd uilng to doct fil
pTnt luins d kc-fitt sute ():
F. olkU F = open (" a.d et', "w")
E . u t Tme is a great haln.\n"
wAuts- t c t U E wit lkap gsiug \n
")
ppud-tect) F.close)
ead - uet
prit " Lda u i t n inte he fiu)
R!
**
Readting ftem a luoct ils wsin Kiadliu ) wil ruHwm a liu rad ) as
TAad sting emthu filu
d ct-read
=
open L' a. tet ", "r") Jst caL totlu
SF. read ) Ust l u
huetow retuu
Prunt ts) icend Call to Lhu nche14
wuL Yitun dicend liiu
F.CloseC) and so eu,
tuct
witt e ading an tuluL
het- Lad l) tll, we wll h a
to a lutp.
RasuLt
ata ultu int
Tim is a r a t ualnFl
9ptn My. tet ", "o")
Kup g6ung. F. wit My name is hesda . \n
xtt Reading E. wit I ° read un tisw 1 . Ih")
rLady
F. wut I u d sudy vcempulev \
Fclss )
ct-rLad ) :
F =cpen (" q. et "r)
S ou re0d- ttoct )
F.adtid)
Pruut ) F pen l" M. tet")
uu - F. Tadliw ()
F. cLeseO
w l Uu
t i e t - r t a d l). prut ind
n E . rAadlin
F.close
Raout
Tme a
LadJict )
Reauwlt
M homL LLs Ch4shka
L rAOd u class
O00 72ITE
us& a
I etudy
cemputens cnanact olata eceuping Mamed placu
aisk
RAOdlinus ) can he usud to r a d tHe wle neud Hi because oala u stakuo
ntiu Centut o Ltu file pumanemly n ALCMdans mccdua
tilLrctuu cLlist o stungs usiug i l I ) . we may
ach
Cpanaud byln otala Loulen ua.
Assignment -1
tus 3 h e n e blw let and Binany l s
1. What is a file? Why do we need a
file?
2. How many types of files
3.
there?
are
T e jils Binauy fil
Differentiate between text files and binary files.
4 How are binary files faster than text files?
S.What extension is given to a text file?
)ut censLat a0. &tauunee dt ussd
6 What cxtension is given to a binary file? chanactn un Uhucn binany olata
Write a program in Python to create
7 about yourself in it.
a text file "person.txt" and write two sentences each l i w u tminalu
8 Write a program in Python to create a text file "myfile.txt" and write List items EOL lEndof lin)
containing your name, address and mobile nurmber.
9. Define a function WRITE() to create a text file "YOU.txt" and write five lines ) wu Us a alulimikThu uis no detimik
about COVID-19. Define a function READ() to read from "YOU.xt" and display
one line at a time. Call both the functions. n w im ln
10. Definea function WRITE() to create a text file "country.Lxt" and write five lines
about our country. Define a function READ() to read from "country.txt" using
readlines() and show the contents on screen. Call both the functions.
3) ut can bt steuud Lean hoT Shod
humaun radabl umaur tadablu
oum am.
u) EctenaLe .tet EclmsuOL bn
Aw Binay ulw u a s t u LthCu t e t TLadlinL )
bicauae hinauy ls o Can Lel wut- troct ):
rLad y Cempuliu nly aund
Fapen
l'You. tt', 'wo')
e n nst stoud win hinnuread- F. wut ' Co vLo 9 stauds CeuonaLY
-ablu om. oliaLase oL9 \n')
F. witt omamon cludu
.tx t
Sumpttmy
gun a ct A , C6Lgh ahouuso
ils bratn ln')
F w i t ThuL uuw u
s .bin Linen to a pmauulty
binauy ilu prLadbelunn peopis durug
Lentaet
F witu Tim tom epsawn
uitin4 to a luct ila4 typicuuy asuud 2
f- &pu puuen tet", w) oouys IuY
F. wiut
F. wut
hanudwemk w aky to
Succsas.l F.wit t t w a y fit ideuifi d tn
on4 s n but pouty.l
F. clae )
Ldteemhuu io19 n )
PTuntt datawitteu u thu Hils du rad- tet):
FGpun (' you.tet ')
Ss *Wetiug list tums t a tuct HlL lu E. radLinu
z
h i l Uus
F p r l myHiu et',w') prui lLin
L hamL -chslntaln', add palual u E . ralinu )
phu ho.9034562.32
F. wuite Linw lL)
witttet
F.CLsl)
PTiut ('list tem wmitte Succissuly)
GOoD t7.217E
Mslo UsL reaollinuD
ou wite Ht : -
GOLAYA PROGRESSIVE PUBLIC SCHOOL
tz pen l'tsunbuy. tet w )
F.wit'India "isa beauHul Count
F. i t l't is ich un Cuutu auol Assignment -2
Hadih' em lh) Define a function COUNT) to read from
F. w i t TL Coutny is Sussnded country.txt" and count the number of lines.
by tu 3 seuäns\n') Define function COUNTTO to
a
Fwite mdia as i t t plans read from
country.txt" and count the number of lines
starting with "T".
t e ln')
u t he Define a function COUNTNTO to read from
nouthounpltus paut
Sudiq is CSUnd uiH "country.txt" and count the number of lines
mLntaius \u') not starting with T.
F.elssO
d e read tesetl): Css
F pem l'Ceuty.tet' ta opelcsuuy txt','y')
i F:readlidl)
f. radlinel)
while Liue
PTint luinn)
Cnt t:1
Feles pYnt 'tetal lins au' Colwt)
wuit ttoet ) F. closL0
Tad terot
F opn ony tk t )
Cotut
GooD R I TE
T'):
i (u[o
: =
Cont t =||
lins stanting fum T , Cotunt)
PTnt " total
. cl
Centuy.txt" r')
Fa Op ltitie
F Ladlinewl)
i i [ a = (7):
ontt
net slonling
prunt l Tolal lius a u L
L m T " , Cont)
GOLAYA PROGRESSIVE PUBLIC SCHOOL
Assignment -4
Write a program to count how many times "to" appears as an
independent word in a text file.
Write a program to count number of capital alphabets in a text
file.
Write a program that appends the contents of one text file to
another. Ask the filenames from the user.
Write a function rem_lower( ) that accepts two filenames. and
copies all lines that do not start with lowercase letter from the
first file into the second file.
Cuws Fa chunl'tcwntytet','')
Cotnt D
S E Lad ()
i i isuppu):
Lsunt Lewt tl
700 P t[lut)
Flosl)
du em- owes ):
ri p u t ("Erlu tist fil namL") lrtnn
F2 v p u t E u sLvid filu hame) Rulatise fa
a peu (f1, ' )
b pen Fa salul Pa Relatue Pat
X a radluuy l)
fo uL X:
talways ugius t s relatwve +o Hu
u (uLo].talsuer) with Hu 'rott toiduw Progums Cuet
Centiuu
else
b. ele wut i) A SLngu peuod ("dot") #C a fodx name
is shund thiw olulbey
b. clss)
d u c t - r a d ():
i nam input Ctmtn tilhami
wo bUlcds ("det det )maw he pareut
foldi
unamu, tr})
Fread Examp 5 elUur pat
elAL)
rem -
k ow)
bacsN
Ibatal f
uct Ownl)
bacen
elkappund- txt ):
Umame 1 uput cutu
Ecampl o bsalutu path
fuwnam
F pen filoname', ta') G:Tbacen l ar
F opun 'd.t ','r') bacem
FaS Fa. rad ) C: 1bacen
Fi wuitt Is)
F TlL0
Fa.clssel) appud tt0
du ttxt -readl): ttyt read )
FOpu lb.txt, 'r)|
P i n t a L y
cls&
wnnt Woukng irectty *wutu a program w Pyther toLwut
rts n cu
Euuy p rO9ram at Stoun i,euc
cgmputi has wsut wokng toa n a y Hlu "a-dat"
olpectouy ovd.
OS get Cúdl) o wite bunas U:
os. thdi) Fu pen "a. dat ", "wb")
Ent tu tourwung untt t nin
List[I,>3,4,5%
eHu h l :
wmpot picklu
imp6t Os
pickl dump ist,flu)
a s gut Gwd D
prunt " st addid to bunany Lt)
C I PHthn 34 wit binay
7 Os-Chdu L'C: uindsus systim 32)
227 Os guroud) pick. Uoad i sLd t ad u bbguct
CI windsusIl system 32
BINARY FILE OPERATION S UutL aPTe Yramm m Pytmm to rLad
a tuuotwe"
The ntion pTDvLdud wn Python tL
Ldichhoany
Lem buany lb.da!
wung readug filt wetk wiH
SUng Mamatbw oluk nOdbun ):
File
Pickle moduteuw usd to Cpul " b dat", "tb")
Rund ebguet filu as Lit
Vmpet plck
alleis D pick Load P l
to steu Pytheu tbjiet w H Pov nt D)
Stu Suehue Fi CLI)
rAad- biul)
u tt proics m a n n c H ens
Ppickle dump() s Cussel to wu
ttu bgcts
L L A - Au
UD. rr nUN the number of tuunes "n ccurs in the tile
ASSIGNMENT (DATA FILE HANDLING - TEXT FILES) For example if the file "DATA TXT"
contains
I mark questions This is my website. I have
1. Differentiate between file modes rt and rb+ with respect to Python
displayed my pretferences in the CtHOICE section
The countmy( ) function should display the output as
2. Differentiate betwcen file modes rt and wt with respect to Python.
"my occurs 2 times"
3. Differentiate between file modes rt and r with respect to Python
7. Write a method in Phyton
4. Differentiate betwecen the
to recad lines from a text file DIARY TXT, and
following those lines, which display
i)f open ('diary. txt', r) starting with an alphabet "P"
are
B1 TLad
uas6 1 Text ypt o til i Mydala
F:witeABC.\n)
GOC twR)TE