I have never seen a single line of Python in my whole life, but to me it seems like the whole program is defining three of something that may be a macro/definition/function that
1. prints the content of a file (from the current file position, despite the name saying "print_all")
2. seeks to the beginning of the file (rewind)
3. prints the content of a file until it reaches a newline
Googling for "python def" reveals the following page, showing that I am right: it is defining three functions doing those things: https://docs.python.org/release/1.5.1p1/tut/functions.html
Defining a function means that you are telling Python about them, but they don't do anything until you call the functions themselves. That is done in the main part of the program:
1. Opens a file (it is now at the beginning of the file) This returns a handle to the file that you use to do further communication with the file. The input to this function seems to be the input that you provided when you are calling the Python script, and is the name of the file.
2. Calling the function to print the content of the file (which is all of the file since you just opened it, also sort of explaining why the function is named "print_all") You are sending in the handle to the file as a parameter. If you were at a different position in the file, it would not have printed all, but everything from the current file position until the end of the file.
3. Calling the function to rewind the file: that means seek to file position 0, the beginning of the file
4. Calling the function to print one line of the file. This is done three times, while incrementing a counter that is irrelevant to the file itself, but it will print as line 1 <something>, 2 <something>, etc... If you had been at a different file position, it would still be printing line 1.., 2.., 3.., even if it really were lines 10.., 11.., 12.. it was printing.
In between these things, there are print that outputs what is actually happening.
That is about it.
Note: there is probably missing the closing of the file, which I would assume should be there, otherwise you would run out of file handles in the long run if you handled a lot of files this way.
An assignment for you:
Can you think of a way to make print_all() not actually print everything?