Question: ```
import os

commands = ['uname -v', 'whoami']

a = 0  
numberIterations = 2    # How to make a command line argument of a while loop number?  
while a < numberIterations:  
    print "#--- Iteration: %s ---#" % a  
    i = 0  
    while i < len(commands):  
        print "$", commands[i]  
        os.system(commands[i])  
        i = i + 1  
    print ""  
    a = a + 1  

```

I want to run the script in this format:  

`./script.py "numberIterations"`

Answer: 
Grab the `str` from `sys.argv` and convert it to an `int`.

```
import sys
try:
  numberIterations = int(sys.argv[1])
except IndexError:
  print "Usage: %s numberIterattions" % sys.argv[0]
  raise SystemExit(1)

```
```
import sys
numberIterations = sys.argv[1] if (len(sys.argv > 0) else _default_value_

```

For more complex command-line interactions (e.g. to provide support for named parameters `./script.py --numIterations=2`) take a look into [optparse](http://docs.python.org/2/library/optparse.html) module or [this tutorial](http://www.tutorialspoint.com/python/python_command_line_arguments.htm)

If using python >= 2.7 use [argparse](http://docs.python.org/2/library/argparse.html#module-argparse) module instead of optparse since optparse is deprecated since python 2.7