In this article, let's look at the python
Tell Method, before we enter the article, we first need to know
Pythontell ()What is it
Tell ()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 Tell () method returns the current position of the file, which is the current position of the file pointer.
Grammar
The tell () method syntax is as follows:
Fileobject.tell (offset[, whence])
return value
Returns the current location of the file.
Instance
The following example demonstrates the use of the Tell () method:
The contents of the file Runoob.txt are as follows:
1:www.runoob.com2:www.runoob.com3:www.runoob.com4:www.runoob.com5:www.runoob.com
To iterate through the contents of a file:
#!/usr/bin/python#-*-coding:utf-8-*-# Open File fo = open ("Runoob.txt", "rw+") print "file name:", Fo.nameline = Fo.readline () pri NT "read data:%s"% (line) # Get current file location pos = Fo.tell () print "Current position:%d"% (POS) # Close File Fo.close ()
The result of the above example output is:
The file name is: runoob.txt The data read is: 1:www.runoob.com current Position: 17
In this article, we explain what is the tell () method, do not understand the words can be hands-on to try, 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.