内容简介:tell() 方法返回文件的当前位置,即文件指针当前位置。
概述
tell() 方法返回文件的当前位置,即文件指针当前位置。
语法
tell() 方法语法如下:
fileObject.tell(offset[, whence])
参数
- 无
返回值
返回文件的当前位置。
实例
以下实例演示了 tell() 方法的使用:
文件 codercto.txt 的内容如下:
1:www.codercto.com 2:www.codercto.com 3:www.codercto.com 4:www.codercto.com 5:www.codercto.com
循环读取文件的内容:
#!/usr/bin/python # -*- coding: UTF-8 -*- # 打开文件 fo = open("codercto.txt", "rw+") print "文件名为: ", fo.name line = fo.readline() print "读取的数据为: %s" % (line) # 获取当前文件位置 pos = fo.tell() print "当前位置: %d" % (pos) # 关闭文件 fo.close()
以上实例输出结果为:
文件名为: codercto.txt 读取的数据为: 1:www.codercto.com 当前位置: 18
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 理解实例方法、类方法、静态方法
- 【MyBatis源码分析】insert方法、update方法、delete方法处理流程(上篇)
- 【MyBatis源码分析】insert方法、update方法、delete方法处理流程(上篇)
- java:方法覆盖与方法重载
- 静态方法、实例化方法与线程安全
- JS数组方法总览及遍历方法耗时统计
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Two Scoops of Django
Daniel Greenfeld、Audrey M. Roy / CreateSpace Independent Publishing Platform / 2013-4-16 / USD 29.95
Two Scoops of Django: Best Practices For Django 1.5 is chock-full of material that will help you with your Django projects. We'll introduce you to various tips, tricks, patterns, code snippets, and......一起来看看 《Two Scoops of Django》 这本书的介绍吧!