Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 2

88 bytes added, 18:57, 25 May 2017
PART 2 - 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>
:#Create a new script called '''~/ops435/lab2/showargs.py''' and place the following content inside<source>
#!/usr/bin/env python3
</source>
:#Run the script and examine the outputby running the Python script without and with arguments:<source>
run showargs.py
run showargs.py testing different arguments
run showargs.py argument1 argument2 argument3
</source>
:#The '''sys.argv''' contains all arguments, '''sys.argv[0]''' contains the name of the script/program, '''sys.argv[1]''' contains the first argument, '''sys.argv[2]''' contains the second argument, etc.
''' Practice Using Arguments '''
13,420
edits