os.write(fd, str, /)
- The write() function writes a given collection of bytes in the str parameter to the file represented by the file descriptor fd.
The return value of the built-in function open() is a file object of type from any of the several I/O wrappers based on the chosen I/O type. e.g., a TextIOWrapper object in case of text I/O, a FileIO object in case of binary I/O without buffering. The write() method on these objects to be called when a file object is obtained through the built-in function open(). The os.write() is to be used when a file descriptor is used to perform low level I/O, typically opened through the os.open().
Number of bytes written to the file.
# Example Python program that uses the low-level I/O
fPath = "/PythonProgs/OneTwoBuckle.txt"
song = """One, two, buckle my shoe
fd = os.open(fPath, fFlags, 0o744)
|Written 132 bytes to /PythonProgs/OneTwoBuckle.txt|