Monday, September 12, 2011

LPTHW - Exercise 13

In this exercise we will learn how to accept command line arguments.



In the script above in the first line we import the 'argv' variable from the 'sys' module. This variable will hold the name of the script and all command line arguments given to it.

We unpack these values and assign them to the variables on the LHS.

Questions:
1. Does importing argv make is available, or does it also turn on the function of accepting command line arguments?

2. Here we assign the values to the variables on the LHS. However, we need to be sure that the command line parameters and the number of variables are the same. This is not always possible, especially when we do not know how many values the user will enter. Perhaps, this issue will be dealt with in a later exercise. I will leave it as is for now, but will try to answer it if it is not dealt with in a later exercise.

No comments:

Post a Comment