Passing variables at runtime

python

Solution

You can use `sys.argv`

test.py

#!/usr/bin/env python

import sys
total = int(sys.argv[1]) +  int(sys.argv[2])
print('Argument List: %s' % str(sys.argv))
print('Total : %d' % total)  

Run the following command:

$ python test.py 123 124
Argument List: ['test.py', 'arg1', 'arg2', 'arg3']
Total : 247

Problem

I wish to pass in some variables into python during run time ``` python add2values.py 123 124 ``` then in the python script it will take those 2 values and add together. OR ``` python add2values.py a=123 b=124 ``` then in the python script it will take those 2 values and add together.

Original source

Related problems