Advertisement



< Prev
Next >



Python - File and File Modes




Python language allows us to perform important disk input/output operations such as -






Advertisement




File Modes


There is a specific file mode for every file operation. These file modes allow us to create, read, write, append or modify a file. Let's see all these different modes in which we could open a file on disk.

File Modes Description
r
Searches for the file and opens it in read mode(default mode), if the file is found.

w
Searches for the file and opens it in write mode. If the file is found, its content are overwritten. If file is not found, a new file is created. Allows you to write to the file.

a
Searches for the file and opens it in append mode i.e. this mode allows you to append new data to the end of a file. If file is not found, a new file is created.

t
Searches for the file and opens the file(if the file is found) in a text mode(default mode) to perform text input/output file operations.

b
Searches for the file and opens the file(if the file is found) in a binary mode to perform binary input/output file operations.

+
Searches for the file, opens it to modify the content of a file by allowing both input and output operations on a file. Should be used in combination with either r, w or a mode.





Please share this article -





< Prev
Next >
< Python - Input/Output Functions
Python - Read a File >



Advertisement

Please Subscribe

Please subscribe to our social media channels for daily updates.


Decodejava Facebook Page  DecodeJava Twitter Page Decodejava Google+ Page




Advertisement



Notifications



Please check our latest addition

C#, PYTHON and DJANGO


Advertisement