Home > Backend Development > Python Tutorial > What is the python os.close() method? What can os.close do?

What is the python os.close() method? What can os.close do?

乌拉乌拉~
Release: 2018-08-17 14:45:43
Original
2622 people have browsed it

In today’s article, we will learn about the python os.close() method. In the next article, I will introduce the close( in python ) Method, maybe you have never seen or used this method, but it doesn’t matter, I will introduce this method well in this article.

Overview

The os.close() method is used to close the specified file descriptor fd.

Grammar

The syntax format of the close() method is as follows:

os.close(fd);
Copy after login

Parameters

## fd – file descriptor.

(This method has no return value.)

Example

The following example demonstrates the use of the close() method:

#!/usr/bin/python
# -*- coding: UTF-8 -*-
import os, sys
# 打开文件
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
#  写入字符串
os.write(fd, "This is test")
# 关闭文件
os.close( fd )
print "关闭文件成功!!"
Copy after login

The output result of executing the above program is:

关闭文件成功!!
Copy after login
The above is all the content of this article. I hope what I said and the examples I gave can be helpful to you.

For more related knowledge, please visit the

Python tutorial column on the php Chinese website.

The above is the detailed content of What is the python os.close() method? What can os.close do?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template