seek()
来源:互联网 发布:酷狗mac添加音乐 编辑:程序博客网 时间:2024/05/16 06:09
seek(0)代表从文件头开始,1表示从当前位置开始,2代表从末尾开始
from sys import argvscript, input_file = argvdef print_all(f): print f.read()def rewind(f): f.seek(0)def print_a_line(line_count, f): print line_count, f.readline()current_file = open(input_file)print "First let's print the whole file: \n"print_all(current_file)print "Now let's rewind, kind of like a tape."rewind(current_file)print "Let's print three lines:"current_line = 1print_a_line(current_line, current_file)current_line = current_line + 1print_a_line(current_line, current_file)current_line = current_line + 1print_a_line(current_line, current_file)print "4", current_file.readline()print "5", current_file.readline()current_file.close()
Xavier@Xavier-PC ~/python_test
$ python ex20.py test_20.txt
First let’s print the whole file:
gege
i
love
u
Now let’s rewind, kind of like a tape.
Let’s print three lines:
1
2 gege
3 i
4 love
5 u
阅读全文
0 0
- seek
- seek
- seek()
- RandomAccessFile.seek
- Ffmpeg seek
- seek function
- seek接口
- python seek()
- python seek()
- mp4 seek
- python seek
- U - Seek the Name, Seek the Fame
- Seek the Name, Seek the Fame(KMP)
- POJ2752 Seek the Name, Seek the Fame
- POJ2752:Seek the Name, Seek the Fame
- poj2752 Seek the Name, Seek the Fame
- Seek the Name, Seek the Fame
- Seek the Name, Seek the Fame(kmp)
- Python编程细节(三)
- 【Linux相识相知】任务计划和周期性任务
- 从头开始搭建一个dubbo+zookeeper平台
- Laravel 学习路线【1】基础目录认识
- java list分组
- seek()
- VMare12.5.7安装Ubuntu16.04.2失败的解决方案
- OC基础一
- Windows下进入到docker容器镜像内部
- 滑动接听慢卡顿分析
- MAVEN包管理工具
- 数据库锁表的分析与解决(三)
- linux xz格式解压
- Android LED数字/电子表字体digital font