Overview:
-
The os.open() implements the Unix function open(). This is a low-level function that accepts Unix file creation modes and file permissions as parameters to create a file descriptor from a given file path.
-
The Python built-in function open() dynamically creates and returns different types of objects based on the chosen I/O mode (text or raw), which is generally suitable for most of the common needs of file I/O.The file descriptor returned by os.open() can be used to perform I/O involving raw bytes or can be used to develop objects and functions to support specialised I/O (e.g., involving text).
Parameters:
path - File path
flags - Flags that are ORed together to specify read, write, create and other similar modes
mode - Octal literal specifying file permissions. The effective mode is given by (mode and (not mask value))
Example:
# Example Python program that uses low level function os.open() # Open a file on a given path # Write bytes to the file using the file descriptor # Read and print raw bytes while bytesRead: os.close(fd) |
Output:
Number of bytes written:11 |