Devin Hight3,141 Points
Why do we need sys.argv exactly?
I'm still unsure about the functionality/necessity of this whole area under the
name == 'main': function. Is it just a way to index the contents of the file?
Chris FreemanTreehouse Moderator 62,625 Points
I would need to see the referenced code to understand how
says.argv is being used. In regular use,
sys.argv refers to the second word on the command line.
argv usually refers to the program name “python”.
Regarding the use of
Keep in mind that any python file may be imported to any other file. The “if
__name__ == "__main__"” idiom is used to tell whether the current file is being executed as the top level module or if has been imported into another Python file.
Each python file has its own namespace to hold variables. The name of the current file is held in this namespace as the variable
__name__. However, if the file was invoked using
python filename.py then, instead of the filename, the string “
__main__” is assigned. So, by using this idiom, the code under this
if statement can be restricted to run if and only if the current file was called directly by the python interpreter as the top module.
Post back if you need more help. Good luck!!!