Python's file Tell () method usage and function parsing (instance)

Source: Internet
Author: User
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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.