I need to run a script with external arguments where first argument should be a int the second an list : example :
python run_eval_ML.py 5 "(2,4,6,8)"
When I run the script I get :
(base) MyPC:ML$ python run_eval_ML.py 5 "(2,4,5,8)"
run_eval_ML.py
5
(2,4,5,8)
param_grid {'n_neighbors': '(2,4,5,8)'}
# First ARGV: 5 : OK
But The second argument should be this type : (2,4,5,8) and not '(2,4,5,8)'
When I assign
var2=sys.argv[2]
and I re assign
param_grid = {'n_neighbors':var2}
I get
param_grid {'n_neighbors': '(2,4,5,8)'}
and not
param_grid {'n_neighbors': (2,4,5,8)}
Thank you in advance if you can help
Rgds Carlos
"2,4,5,8"and usesys.argv[2] .split(',')to create list. If you need numbers then you have to convert to integervar2 = [int(x) for x in sys.argv[2] .split(',')]orvar2 = list(map(int, sys.argv[2] .split(',')))"5"not integer5so you may have to convert it too.