Python | os.open() method
OS module in Python provides functions for interacting with the operating system. OS comes under Python’s standard utility modules. This module provides a portable way of using operating system dependent functionality.
os.open() method in Python is used to open a specified file path and set various flags according to the specified flags and its mode according to specified mode.
This method returns a file descriptor for newly open file. The returned file descriptor is non-inheritable.
Syntax: os.open(path, flags, mode = 0o777, *, dir_fd = None)
Path: A path-like object representing the file system path. This is the file path to be opened.
A path-like object is a string or bytes object which represents a path.
flags: This parameter specify the flags to be set for newly opened file.
mode (optional): A numeric value representing the mode of the newly opened file. The default value of this parameter is 0o777 (octal).
dir_fd (optional): A file descriptor referring to a directory.
Return Type: This method returns a file descriptor for newly opened file.
method to open a file path
os.O_RDWR | os.O_CREAT
(path, flags, mode)
"File path opened successfully."
"GeeksforGeeks: A computer science portal for geeks."
"String written to the file descriptor."
"\nString read from the file descriptor:"
"\nFile descriptor closed successfully."
File path opened successfully.
String written to the file descriptor.
String read from file descriptor:
GeeksforGeeks: A computer science portal for geeks.
File descriptor closed successfully.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!