Learning Python: The Ultimate Guide for Beginners to Coding with Python with Useful Tools


Modes for Opening a File in Python



Download 2,02 Mb.
Pdf ko'rish
bet98/126
Sana01.01.2022
Hajmi2,02 Mb.
#285662
1   ...   94   95   96   97   98   99   100   101   ...   126
Bog'liq
Learning Python The Ultimate Guide for Beginners to Coding with

Modes for Opening a File in Python
Modes
Meaning
r
This  opens  a  file  for  reading
purposes  only.  The  default  mode  is
to  place  the  file  pointer  at  the
beginning of the file
r+
This opens a file for both writing and
reading.  Similar  to  the  r  mode,  the


pointer is at the beginning of the file
rb
If  you  want  to  open  a  file  in  binary
format,  then  you  have  to  use  the  rb
mode.  Furthermore,  you  place  the
point at the starting point of the file
rb+
Open  files  for  both  writing  and
reading in binary format
w
Open files for writing purposes only.
if the file doesn’t exist, it will create
a new file, but if it does exist, it will
overwrite the file
wb
This  opens  a  file  for  writing  in
binary format. It also overwrites and
creates  new  files  depending  on  the
existence of the file
w+
This opens a file for both writing and
reading  purposes.  It  also  overwrites
and  creates  new  files  depending  on
the existence of the file.
wb+
Both  write  and  read  files  in  binary
format.  Overwrites  and  create  new
files  based  on  the  existence  of  the
file.
a
This  opens  a  file  for  appending.  If
the  file  exists,  the  pointer  is
positioned at the end of the file
a+
Opens  file  for  both  reading  and
appending purposes.
ab
Opens  file  for  appending  in  binary
format.
ab+
If you want to read and append files
in binary format, then the ab+ mode


is  relevant.  If  the  file  exists,  the
pointer is positioned at the file end.


Exercise to Try
Write  a  program,  which  requests  a  particular  user  to  insert  the
choice of their rental car. Print a message that displays the choice
of their rental car.
Write another program, which requests for a number and print if
the number is a multiple of 9 or not
Write a simple program that asks a user the number of a person
in a queue in a bank. If the user's reply is above 8, it should print
a  message  that  they  have  to  wait  or  go  home  and  return
tomorrow.

Download 2,02 Mb.

Do'stlaringiz bilan baham:
1   ...   94   95   96   97   98   99   100   101   ...   126




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish