Changes

Jump to: navigation, search

OPS435 Python Lab 2

4 bytes removed, 19:21, 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 your Python script can store the following:<ul><li>'''sys.argv''' - stores all argument data</li><li>'''sys.argv[0]''' - stores the name of the script/program</li><li>'''sys.argv[1]''' - 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