Python中tell()方法的使用详解


Posted in Python onMay 24, 2015

 tell()方法返回的文件内的文件读/写指针的当前位置。
语法

以下是tell()方法的语法:

fileObject.tell()

参数

  •     NA

返回值

此方法返回该文件中读出的文件/写指针的当前位置。
例子

下面的例子显示了tell()方法的使用。

#!/usr/bin/python

# Open a file
fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name

# Assuming file has following 5 lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line

line = fo.readline()
print "Read Line: %s" % (line)

# Get the current position of the file.
pos = fo.tell()
print "Current Position: %d" % (pos)

# Close opend file
fo.close()

当我们运行上面的程序,它会产生以下结果:

Name of the file: foo.txt
Read Line: This is 1st line

Current Position: 18

Python 相关文章推荐
python正则表达式去掉数字中的逗号(python正则匹配逗号)
Dec 25 Python
Linux 下 Python 实现按任意键退出的实现方法
Sep 25 Python
用yum安装MySQLdb模块的步骤方法
Dec 15 Python
Python爬虫实现网页信息抓取功能示例【URL与正则模块】
May 18 Python
Python3.遍历某文件夹提取特定文件名的实例
Apr 26 Python
python实现扫描日志关键字的示例
Apr 28 Python
利用anaconda保证64位和32位的python共存
Mar 09 Python
parser.add_argument中的action使用
Apr 20 Python
Python如何批量生成和调用变量
Nov 21 Python
Python利用imshow制作自定义渐变填充柱状图(colorbar)
Dec 10 Python
Python从MySQL数据库中面抽取试题,生成试卷
Jan 14 Python
Python django中如何使用restful框架
Jun 23 Python
在Python中操作文件之seek()方法的使用教程
May 24 #Python
简单介绍Python中的readline()方法的使用
May 24 #Python
在Python中操作文件之read()方法的使用教程
May 24 #Python
在Python中使用next()方法操作文件的教程
May 24 #Python
在Python程序中操作文件之isatty()方法的使用教程
May 24 #Python
讲解Python中fileno()方法的使用
May 24 #Python
在Python程序中操作文件之flush()方法的使用教程
May 24 #Python
You might like
[原创]效率较高的php下读取文本文件的代码
2008/07/02 PHP
php猴子选大王问题解决方法
2015/05/12 PHP
PHP编写的图片验证码类文件分享
2016/06/06 PHP
thinkPHP框架可添加js事件的分页类customPage.class.php完整实例
2017/03/16 PHP
ThinkPHP5.1表单令牌Token失效问题的解决
2019/03/22 PHP
javascript window.opener的用法分析
2010/04/07 Javascript
Juqery Html(),append()等方法的Bug解决方法
2010/12/13 Javascript
浅谈jQuery中 wrap() wrapAll() 与 wrapInner()的差异
2014/11/12 Javascript
JS数组array元素的添加和删除方法代码实例
2015/06/01 Javascript
js中遍历Map对象的方法
2016/07/27 Javascript
详解nodejs 文本操作模块-fs模块(一)
2016/12/22 NodeJs
微信小程序chooseImage的用法(从本地相册选择图片或使用相机拍照)
2018/08/22 Javascript
Vue创建头部组件示例代码详解
2018/10/23 Javascript
Easyui 关闭jquery-easui tab标签页前触发事件的解决方法
2019/04/28 jQuery
详解Vue中的基本语法和常用指令
2019/07/23 Javascript
vue中如何添加百度统计代码
2020/12/19 Vue.js
python的id()函数介绍
2013/02/10 Python
python实现俄罗斯方块
2018/06/26 Python
django 2.2和mysql使用的常见问题
2019/07/18 Python
python机器学习包mlxtend的安装和配置详解
2019/08/21 Python
Python常用模块os.path之文件及路径操作方法
2019/12/03 Python
python 实现学生信息管理系统的示例
2020/11/28 Python
data:image data url 文件转为Blob上传后端的方法
2019/07/16 HTML / CSS
美国当红的名品折扣网:Gilt Groupe
2016/08/15 全球购物
英国手机零售商:Metrofone
2019/03/18 全球购物
办公室文秘自我评价
2013/09/21 职场文书
养殖人员的创业计划书范文
2013/12/26 职场文书
新员工欢迎词
2014/01/12 职场文书
生物制药自我鉴定
2014/01/25 职场文书
合作意向书模板
2014/03/31 职场文书
教师三严三实学习心得体会
2014/10/11 职场文书
2014年新农村建设工作总结
2014/12/01 职场文书
2015纪念九一八事变84周年演讲稿
2015/03/19 职场文书
离婚代理词范文
2015/05/23 职场文书
合作协议书格式范本
2016/03/21 职场文书
前端canvas中物体边框和控制点的实现示例
2022/08/05 Javascript