import sys
def fun( a=7, b=1 ):
print a, b
fun()
fun( a=5 )
fun( sys.argv[1:] )
The first fun() prints out '7,1', the second prints out '5,1', but the third prints out '['a=8', 'b=6'] 1]'. I would like to be able to call my program with
python my_program.py a=5 b=6
to change the value of the printed a and b. But this doesn't work since sys.argv[1] is a list of strings.
Is there any way to convert the the string list to a form the function can understand?