# -*- coding: utf-8 -*-
# @Author: yt
# @Date: 2018-05-15 13:55:12
# @Last Modified by: yt
# @Last Modified time: 2018-05-15 14:57:53
from sys import argv
script,input_file = argv
#读取文件的所有内容
def print_all(f):
print f.read()
#设置文件指针到文件起始位置
def rewind(f):
f.seek(0)
#读出指定行的文件内容
def print_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 "rewind,seek(0)"
rewind(current_file)
print "Let's print three lines:"
current_line = 1
print_line(current_line, current_file)
current_line += 1
print_line(current_line,current_file)
current_line += 1
print_line(current_line,current_file)
运行结果如下:seek(number): 设置文件的指针到指定的number处