13,420
edits
Changes
→PART 2 - Arguments
print(sys.argv) # tells us our arguments
sys.exit() # will immediately end our script when run, ignoring the remaining lines in the Python script
</source>Note that the '''sys.exit()''' function will be useful later in this lab, make sure you write it down in your notes.<br><br>Instead of using the '''input() ''' function to prompt the user for data, we can use the '''sys .argv''' function to obtain store data from as a result of running the Python script insteadwith arguments. The '''sys.argv''' function (within the running Python script) stores all arguments, '''sys.argv[0]''' stores the name of the script/program, '''sys.argv[1]''' store the first argument, '''sys.argv[2]''' stores the second argument, etc.<br><br>
:#Create a new script called '''~/ops435/lab2/showargs.py''' and add the following content:<source>
#!/usr/bin/env python3