YouTip LogoYouTip

Python3 Os Close

# Python3.x Python3 os.close() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#) * * * ### Overview The os.close() method is used to close the specified file descriptor fd. ### Syntax The syntax for the **close()** method is as follows: os.close(fd); ### Parameters * **fd** -- The file descriptor. ### Return Value This method does not return a value. ### Example The following example demonstrates the use of the close() method: ## Example #!/usr/bin/python3 import os,sys # Open the file fd =os.open("foo.txt",os.O_RDWR|os.O_CREAT) # Write a string os.write(fd,"This is test") # Close the file os.close( fd ) print("File closed successfully!!") The output of the above program is: File closed successfully!! [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Python3 Os DupPython3 Os Close β†’