This article mainly introduces the use of the "Tell" method in Python, is the basic knowledge in Python introductory learning, the need for friends can refer to the
The current position of the file read/write pointer in the file returned by the tell () method.
Grammar
The following is the syntax for the Tell () method:
?
Parameters
NA
return value
This method returns the current position of the file/write pointer that is read in the file.
Example
The following example shows the use of the Tell () method.
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21-22 |
#!/usr/bin/python # Open a file fo = open ("Foo.txt", "rw+") print "Name of the file:", Fo.name # assuming file has fo Llowing 5 Lines # this are 1st line # this is 2nd line # this is 3rd line # the IS 4th . ReadLine () print "Read line:%s"% [line] # get the ' current position ' the ' file. pos = Fo.tell () print ' Current Position:%d '% (POS) # Close Opend file Fo.close () |
When we run the above program, it produces the following results:
?
1 2 3 4 |
Name of the File:foo.txt Read Line:this is 1st line current position:18 |