Open main menu

CDOT Wiki β

Changes

OPS435 Python Lab 2

59 bytes added, 17:47, 25 May 2017
PART 2 - Arguments
:An argument is a value that is passed to a program or passed to a function that can be used for processing within that program or function. In the previous section, you passed an argument to the '''input()''' function. In this section, you will learn how to pass an argument to your Python script, but this time, this argument will be passed when we execute your Python script from the bash shell.
'''Perform the following steps:''' :#Access your ipython3 shell:<source>ipython3</source>In order to read arguments in Python, we will need to '''import special variables''' from the system. This is a standard 'library' of code provided by the developers of Python. By issuing '''import sys''', you have loaded code written by another person, each 'library' that gets loaded will give us extra functionality in our program. This is done by issuing the import sys function within your ipython3 shell.
:In order to read arguments in Python, we will need to '''import special variables''' from the system. This is a standard 'library' of code provided by the developers of Python. By issuing '''import sys''', you have loaded code written by another person, each 'library' that gets loaded will give us extra functionality in our program. This is done by issuing the import sys function within your ipython3 shell.
:#Issue following to access your ipython3 shell and import special variables:<source>
ipython3
import sys
</source>
:#To inspect this library and look at all that it contains we can use the 'dir()' function. This can be used to inspect any library(and more) looking at all the functions and values contained within.<source>
dir(sys)
13,420
edits