Python Open() function
Learn to use Python's open() function to open and read files. Discover how to handle file contents as Python objects in this tutorial at rrtutors.com.
The open() function is the Python built-in function that is used to open all the internally stored files. This function takes the name of the file and returns the file contents in the form of python objects.
Now let's take a look at the syntax of the open() function.
Syntax
|
open(file, mode) |
Where:
File- this is the4 name of the file to be opened
Mode- this specifies the mode of the file to be opened. The mode includes: read-only, writing on/over, or append.
Example
In the example below, we will create a text file and read that file.
|
read_file = open("Python.txt", "w") |
Output
When the open() function is called, Python.txt is opened.
![]() |
