-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex20.py
More file actions
40 lines (24 loc) · 786 Bytes
/
Copy pathex20.py
File metadata and controls
40 lines (24 loc) · 786 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Exercise 20, Learning Python the Hard Way"""
from sys import argv
SCRIPT, INPUT_FILE = argv
def print_all(myfile):
"""Print the whole file"""
print myfile.read()
def rewind(myfile):
"""Rewind to the start of the file"""
myfile.seek(0)
def print_a_line(line_count, myfile):
"""Print one of the lines"""
print line_count, myfile.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 = 1
print_a_line(CURRENT_LINE, CURRENT_FILE)
CURRENT_LINE = CURRENT_LINE + 1
print_a_line(CURRENT_LINE, CURRENT_FILE)
CURRENT_LINE = CURRENT_LINE + 1
print_a_line(CURRENT_LINE, CURRENT_FILE)