您的位置:首页 > 编程语言 > Python开发

Python Exercise #20

2013-06-02 17:19 651 查看
#!/usr/bin/python      # exact position of python
#!/usr/bin/env python  # position of python in enviornment
# -*- coding:utf-8 -*- # coding
# Purpose: Functions And Files

from sys import argv

script, input_file = argv

def 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 line:"

current_line = 1
print_a_line(current_line, current_file)

current_line += 1
print_a_line(current_line, current_file)

current_line += 1
print_a_line(current_line, current_file)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: