Unsure of my python explanatory comments
Question: I'm doing Learn Python the Hard Way exercise 15

A study drill is to explain every line with comments, but I feel unsure of my
explanations. I'm looking for corrections to my mistakes and improvements.
Correct term usage is my biggest worry, especially when it comes to variables
and file-objects.

this is the plain code

    
    
    from sys import argv
    
    script, filename = argv
    
    txt = open(filename)
    
    print "Here's your file %r:" % filename
    print txt.read()
    
    print "Type the filename again:"
    file_again = raw_input("> ")
    
    txt_again = open(file_again)
    
    print txt_again.read()
    

This is the code with my inadequate explanatory comments.

    
    
    #the following is what is run from commandline
    #each word(?) following python is an argument
    #python ex15.py ex15_example.txt
    
    
    #imports the "argument variable" module from the sys package
    from sys import argv
    
    #assigns commandline arguments to variables 
    script, filename = argv
    
    #creates "txt" variable that creates a file-object of the filename variable
    txt = open(filename)
    
    #prints written string followed by filename variable
    print "Here's your file %r:" % filename
    #reads and prints variable "txt" which is a file object
    print txt.read()
    
    #prints string asking for raw_input
    print "Type the filename again:"
    #prompts you for raw_input and takes your raw_input and makes file_again variable
    file_again = raw_input ("> ")
    
    #creates txt_again file-object of file_again variable
    txt_again = open(file_again)
    
    #reads and prints txt_again file-object
    print txt_again.read()
    


Answer: The purpose of these comments is only for you to write them and, by doing so,
learning and remembering what each line does. they don't have to follow rules
of proper commenting (not like anybody comments every single line in real
code, what'd be using python for then? LOL)

So, with that out of the way, lemme go through each line like you did.

    
    
    #the following is what is run from commandline
    #each word(?) following python is an argument
    #python ex15.py ex15_example.txt
    # (Correct. )
    
    #imports the "argument variable" module from the sys package
    # (It doesn't work like that. sys is a module, 
    # meaning a sis.py file stored somewhere else is accessed and interpreted. 
    # And argv is an object declared within 
    # said file (could be a class, a global variable, etc.
    # for example. in this case, it's the list of command parameters. )
    from sys import argv
    
    #assigns commandline arguments to variables 
    # (Yeah, since he's doing this, it means argv has 2 items inside, and 
    # each is assigned to the respective variable).
    script, filename = argv
    
    #creates "txt" variable that creates a file-object of the filename variable
    #(Yup)
    txt = open(filename)
    
    #prints written string followed by filename variable
    #(This is a formatted string, similar to how you use printf in C.
    # If you don't know them now, you will later, probably.)
    print "Here's your file %r:" % filename
    #reads and prints variable "txt" which is a file object
    #(the method 'read' basically goes through the remaining unread
    #lines and returns them as a big-ass string, which is then printed
    # by you)
    print txt.read()
    
    #prints string asking for raw_input
    print "Type the filename again:"
    #prompts you for raw_input and takes your raw_input and makes file_again variable
    # (yup, nothing to see here...)
    file_again = raw_input ("> ")
    
    #creates txt_again file-object of file_again variable
    # (yup)
    txt_again = open(file_again)
    
    #reads and prints txt_again file-object
    # (no big surprises here. BTW, if you use txt.read() again, you'll get
    # an empty string. If you already know iterators from some other language,
    # think of file objects as iterators of a file. Once they are used once,
    # you need another one (you can reset this one, though, with some other method).
    print txt_again.read()
    

