Changes

Jump to: navigation, search

OPS435 Python Lab 2

44 bytes added, 18:33, 25 May 2017
PART 2 - Arguments
print(sys.version) # tells us our python version
print(sys.platform) # tells us our operating system platform
print(sys.argv) # tells us our argumentsor shell version if issued from shellsys.exit() # will immediately end our the running Python 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>
:#Create a new script called '''~/ops435/lab2/showargs.py''' and add the following content:<source>
13,420
edits

Navigation menu