num_of_runs = sys.argv[1]
num_of_runs is a string at this point.
while self.run_number <= self.num_of_runs:
You are comparing string and int here.
An easy way to fix this is to convert it to int
num_of_runs = int(sysargv[1])
Another way to handle this is to use argparser .
import argparse parser = argparse.ArgumentParser(description='The program does bla and bla') parser.add_argument( 'my_int', type=int, help='an integer for the script' ) args = parser.parse_args() print args.my_int print type(args.my_int)
Now, if you run the script as follows:
./my_script.py 20
Output:
20
Using argparser also provides the -h option by default:
python my_script.py -h usage: i.py [-h] my_int The program does bla and bla positional arguments: my_int an integer for the script optional arguments: -h, --help show this help message and exit
See the argparser documentation for more information.
Note. The code I used is from the argparser documentation, but has been slightly modified.
source share