Created
December 14, 2016 19:04
-
-
Save clamytoe/0bd4a5b0149d36c148b99e8ba5756cb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# linkedin Python Community | |
# Python the Hard Way, Lesson 20 | |
# Sample code | |
from sys import 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()) | |
def main(): | |
input_file = argv[1] | |
with open(input_file, 'r', encoding='utf-8') as current_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 | |
for x in range(3): | |
print_a_line(current_line + x, current_file) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Response to try and help out a fellow Pythonista.