Python open() Function
Example
Open a file and print the content:
f = open("demofile.txt", "r")
print(f.read())
Try it Yourself »
Definition and Usage
The open()
function opens a file, and
returns it as a file object.
Read more about file handling in our chapters about File Handling.
Syntax
open(file,
mode)
Parameter Values
Parameter | Description |
---|---|
file | The path and name of the file |
mode | A string, define which mode you want to open the file in:
In addition you can specify if the file should be handled as binary or text mode
|
Related Pages
Learn how to open files in our Read Files Tutorial
Learn how to write/create files in our Write/Create Files Tutorial
Learn how to delete files in our Delete Files Tutorial