File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ from sys import argv
2+
3+ script , input_file = argv
4+
5+ def print_all (f ):
6+ print f .read ()
7+
8+ # seek(n) to read a file's content from byte-n
9+ def rewind (f ):
10+ f .seek (0 )
11+
12+ def print_a_line (line_count , f ):
13+ print line_count , f .readline ()
14+
15+ current_file = open (input_file )
16+
17+ print "First let's print the whole file:\n "
18+ print_all (current_file )
19+
20+ print "Now let's rewind, kind of like a tape."
21+ rewind (current_file )
22+
23+ print "Let's print three lines:"
24+ current_line = 1
25+ print_a_line (current_line , current_file )
26+
27+ current_line = current_line + 1
28+ print_a_line (current_line , current_file )
29+
30+ current_line = current_line + 1
31+ print_a_line (current_line , current_file )
32+
33+ current_file .close ()
You can’t perform that action at this time.
0 commit comments