YouTip LogoYouTip

Os Close

# Python2.x Python os.close() Method [![Image 3: Python File Methods](#) Python 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: #!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # Open file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )# Write string os.write(fd, "This is test")# Close file os.close( fd )print "File closed successfully!!" The output of the above program is: File closed successfully!! [![Image 4: Python File Methods](#) Python OS File/Directory Methods](#)
← Rust Data TypesRust Println β†’