File Modes in Python ( r+, w+, a+, rb, wb ) | Crack IT With Anu - Tutorial #64
In this video tutorial, we will discuss the file modes in Python (r+, w+, a+, rb, wb).
1. r+ : read and write without truncating
Behaviour :
a) Requires the file to already exist.
b) Reads and writes allowed
c) Pointer starts at the beginning.
d) Overwrites existing data when writing.
e) Writing after reading requires seek () if you want to change the write position.
Checkout the practical example of "r+" mode in python
-----------------
2. w+ : write and read ( Truncates immediately )
Behaviour :
a) Creates the files if it does not exist.
b) Clear contents if the file exists.
c) Pointer starts at beginning.
d) Good When you want a fresh start but also need to read what you've written.
Check the practical example of "w+" mode in python
-----------------
3. a+ : Append and Read
Behaviour :
a) Creates a file if it doesn't exist.
b) reading starts from the beginning, but writing always happens at the end.
c) Pointer starts at the end by default.
d) Cannot overwrite existing content, only appends.
Check the practical example of "a+" mode in python
-----------------
4. rb and wb modes
These are file modes used when working with binary files like images, audio, video, pdf etc.
a) rb: Read Binary
- Opens file for reading only
- Read the contents as raw bytes, not text.
Commonly used :
- Images ( .jpg, .png )
- Audio ( .mp3 )
- Video ( .mp4 )
- PDF Files
"rb" is needed when reading non-text files, so nothing gets corrupted.
Also Check out the practical example of "rb" mode in python
b) wb - Write Binary
with open ("copy.png", "w") as f:
f.write ( data)
- Opens the file for writing binary data
- If the file exist it overwrites
- If it doesn't exist, it creates a new one.
- Also used for binary files like images, audio, video etc
#crackITwithAnu #filemodesinpython #binarymodes #pythonfilehandling #r+mode #w+mode #a+mode #rbmode #wbmode #rbandwbmodes #learnpython #pythonprogramming
Видео File Modes in Python ( r+, w+, a+, rb, wb ) | Crack IT With Anu - Tutorial #64 канала Crack IT with Anu
1. r+ : read and write without truncating
Behaviour :
a) Requires the file to already exist.
b) Reads and writes allowed
c) Pointer starts at the beginning.
d) Overwrites existing data when writing.
e) Writing after reading requires seek () if you want to change the write position.
Checkout the practical example of "r+" mode in python
-----------------
2. w+ : write and read ( Truncates immediately )
Behaviour :
a) Creates the files if it does not exist.
b) Clear contents if the file exists.
c) Pointer starts at beginning.
d) Good When you want a fresh start but also need to read what you've written.
Check the practical example of "w+" mode in python
-----------------
3. a+ : Append and Read
Behaviour :
a) Creates a file if it doesn't exist.
b) reading starts from the beginning, but writing always happens at the end.
c) Pointer starts at the end by default.
d) Cannot overwrite existing content, only appends.
Check the practical example of "a+" mode in python
-----------------
4. rb and wb modes
These are file modes used when working with binary files like images, audio, video, pdf etc.
a) rb: Read Binary
- Opens file for reading only
- Read the contents as raw bytes, not text.
Commonly used :
- Images ( .jpg, .png )
- Audio ( .mp3 )
- Video ( .mp4 )
- PDF Files
"rb" is needed when reading non-text files, so nothing gets corrupted.
Also Check out the practical example of "rb" mode in python
b) wb - Write Binary
with open ("copy.png", "w") as f:
f.write ( data)
- Opens the file for writing binary data
- If the file exist it overwrites
- If it doesn't exist, it creates a new one.
- Also used for binary files like images, audio, video etc
#crackITwithAnu #filemodesinpython #binarymodes #pythonfilehandling #r+mode #w+mode #a+mode #rbmode #wbmode #rbandwbmodes #learnpython #pythonprogramming
Видео File Modes in Python ( r+, w+, a+, rb, wb ) | Crack IT With Anu - Tutorial #64 канала Crack IT with Anu
Комментарии отсутствуют
Информация о видео
16 апреля 2025 г. 19:13:30
00:24:29
Другие видео канала