Today's article let's look at the close in Python
, before we go into the article we first need to know what
pythonclose is,
what does close mean , It can be used in Python programming where it can play a role. These things we can all learn in today's article.
Overview :
The close () method is used to close an open file. The closed file can no longer read or write, or it will trigger a valueerror error. The close () method allows calls multiple times.
When the file object is referenced to manipulate another file, Python automatically shuts down the file object before it. Using the Close () method to close a file is a good habit.
Grammar
The close () method syntax is as follows:
Fileobject.close ();
(The method has no return value)
Instance
The following example demonstrates the use of the Close () method:
#!/usr/bin/python#-*-coding:utf-8-*-# Open File fo = open ("Runoob.txt", "WB") print "file name:", fo.name# close file Fo.close ()
The result of the above example output is:
File name is: runoob.txt
In this article, we understand what is close (), do not understand the words in fact, they can try to do, after all, hands-on practice is the best way to verify the learning. Finally, I hope that this article will give you a little help in learning about Python.
For more information, please visit the PHP Chinese Web Python tutorial section.