Changes

Jump to: navigation, search

OPS435 Python Lab 2

102 bytes added, 18:20, 25 May 2017
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 store data as a result of running the Python script with arguments. The '''sys.argv''' function (, when used within the running your Python script) can store the following:<ul><li>'''sys.argv''' - stores all arguments, argument data</li><li>'''sys.argv[0]''' - stores the name of the script/program, </li><li>'''sys.argv[1]''' store - stores the first argument, </li><li>'''sys.argv[2]''' - stores the second argument, </li><li>etc...</li></ul><br><br>
:#Create a new script called '''~/ops435/lab2/showargs.py''' and add the following content:<source>
#!/usr/bin/env python3
13,420
edits

Navigation menu