Skip to content

Instantly share code, notes, and snippets.

@clamytoe
Created December 14, 2016 19:04
Show Gist options
  • Save clamytoe/0bd4a5b0149d36c148b99e8ba5756cb8 to your computer and use it in GitHub Desktop.
Save clamytoe/0bd4a5b0149d36c148b99e8ba5756cb8 to your computer and use it in GitHub Desktop.
# 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()
@clamytoe
Copy link
Author

Response to try and help out a fellow Pythonista.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment