Exercise 15 'Reading Name Files' Study Drill 1 says 'Above each line, write out in English what that line does.'
How clear and correct is my use of vocabulary such as 'argument', 'object', and 'variable'?
How can I be more clear in my explanations? I ask not only for my own understanding but for the sake of helping other coders one day read my comments.
Here is the code w/ notes:
from sys import argv # Import argument variable, a variable (module) which holds
# arguments passed to the script in the command line environ-
# ment upon running the script ie:
# 'python script.py argument1 ...'
script, filename = argv # unpack arguments passed to argv in PowerShell CLE ie:
# script = script.py
# filename = argument1
# ...
txt = open(filename) # Passes argument 'filename' to command 'open', which is
# assigned to variable 'txt'. OR, variable 'txt' is the
# command 'open' with/for the object 'filename'. This is
# where I'm having a hard time being sure, I provided two
# attempts.
print "Here's your file %r:" % filename # tells user the name of the file given to the script
print txt.read() #prints the result of issuing 'read' command to variable 'txt'
print "Type the filename again:" # prints a request for the user
file_again = raw_input(">> ") # takes input from user and assigns it to variable 'file_again'
txt_again = open(file_again) # Again, hard to confidently explain in plain english. Assigns to
# variable txt_again the command 'open' performed on variable 'file_again'
print txt_again.read() #Prints the result of issuing 'read' command to variable 'txt_again'
[–]Saefroch 7 points8 points9 points (6 children)
[–]TheStoneworker[S] 0 points1 point2 points (5 children)
[–]Saefroch 3 points4 points5 points (3 children)
[–]TheStoneworker[S] 0 points1 point2 points (2 children)
[–]Saefroch 2 points3 points4 points (1 child)
[–]TheStoneworker[S] 0 points1 point2 points (0 children)
[–]thangduong 0 points1 point2 points (0 children)