os.close(fd)
fd -- 這是該檔案的檔案描述符
這個方法沒有返回值
#!/usr/bin/python3 import os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # Write one string line="this is test" # string needs to be converted byte object b=str.encode(line) os.write(fd, b) # Close opened file os.close( fd ) print ("Closed the file successfully!!")
Closed the file successfully!!