Python os.close() Method
Example
Close a file after it has been opened:
#Import os Library
import os
# Open a file
fd = os.open("file.txt", os.O_RDWR|os.O_CREAT)
# Write a string
os.write(fd, "This is test data")
# Close opened file
os.close(fd)
Definition and Usage
The os.close() method closes the specified file descriptor.
Syntax
os.close(fd)
Parameter Values
| Parameter | Description |
|---|---|
| fd | Required. The file descriptor to be closed. |
Technical Details
| Return Value: | None |
|---|---|
| Python Version: | 1.6 |