Python os.fdopen() Method
Example
Return an open file object connected to a file:
# Import os Library
import os
# Open file
fd = os.open("test.txt", os.O_RDWR|os.O_CREAT)
# Get a file object for the file
fo = os.fdopen(fd, "w+")
# Write something on open file
fo.write( "This is a test content for w3schools")
# Close file
fo.close()
Definition and Usage
The os.fdopen()
method returns an open file object connected to a file.
Note: Available on both WINDOWS and UNIX platforms.
Syntax
os.fdopen(fd, mode, bufsize)
Parameter Values
Parameter | Description |
---|---|
fd | Required. A file descriptor of a connected file |
mode | Optional. Sets how the file is to be opened ("r" for reading, "w" for writing, and "a" for appending |
bufsize | Optional. Sets the file's desired buffer size: 0 = unbuffered, 1 = line buffered, any other positive value = use a buffer of that size, in bytes. |
Technical Details
Return Value: | An object value, representing an open file object connected to a file |
---|---|
Python Version: | pre-2.6 |