Python open() Function
Example
Open the file and print the content:
f = open("demofile.txt", "r") print(f.read())
Definition and Usage
The open() function opens a file and returns it as a file object.
Please learn more about file handling in our file handling chapter.
Syntax
open(file, mode)
Parameter Value
Parameter | Description |
---|---|
file | The path or name of the file. |
mode |
String, define the mode in which you want to open the file:
Additionally, you can specify whether the file should be processed in binary or text mode
|
Related Pages
Tutorial:How to Read File
Tutorial:How to Write/ Create File
Tutorial:How to Delete File