Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 2

5 bytes added, 11:53, 1 August 2017
PART 2 - Arguments
sys.exit() # will immediately end the running Python script, ignoring the remaining lines in the Python script
</source>
<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>
:#Create a new script called '''~/ops435/lab2/showargs.py''' and add the following content:<source>