command line args make cdp parser forget about param file
Closed this issue · 4 comments
doutriaux1 commented
sript
from __future__ import print_function
import cdp
parser = cdp.cdp_parser.CDPParser()
parser.add_argument("-a","--Aarg",default=7,help="A value")
parser.add_argument("-b","--Barg",default=8,help="A value")
parser.add_argument("-c","--Carg",default=9,help="A value")
parser.add_argument("-d","--Darg",default=6,help="A value")
P = parser.get_parameters()[0]
print("A:",P.Aarg)
print("B:",P.Barg)
print("C:",P.Carg)
print("D:",P.Darg)
param file (myparam.py):
Aarg=10
Barg=11
Carg=12
Darg=13
running with params.py:
doutriaux1@crunchy:[~]:[20528]> python test_cdp_param.py -p myparam.py
A: 10
B: 11
C: 12
D: 13
running with params and args:
doutriaux1@crunchy:[~]:[20528]> python test_cdp_param.py -p myparam.py --Aarg=78
A: 78
B: 8
C: 9
D: 6
B, C, D have been ignored
zshaheen commented
@doutriaux1 That's because we have default values. When you run with one of the arguments (--Aarg
), the default values defined in the add_argument
function are used, for all of the command line parameters.
So if we don't want to use the command line argument defaults, please try the following with the latest code on master (it has a fix, for when you use an equal sign, ex: --Aarg=78
):
P = parser.get_parameters(cmd_default_vars=False)[0]
I get the following:
(acme_diags_env_dev) shaheen2@acme1:~/charles_peter_bug$ python driver.py -p myparam.py
A: 10
B: 11
C: 12
D: 13
(acme_diags_env_dev) shaheen2@acme1:~/charles_peter_bug$ python driver.py -p myparam.py --Aarg=78
A: 78
B: 11
C: 12
D: 13
doutriaux1 commented
@zshaheen what happen if you yank say "B" from params.py?
doutriaux1 commented
@zshaheen with this if you do not provide ALL the arguments it fails:
Aarg=10
Barg=11
Darg=13
(cdat8) doutriaux1@loki:[~]:[32745]> python test_cdp_xtra_args.py -p myparams.py --Aarg=67
A: 10
B: 11
Traceback (most recent call last):
File "test_cdp_xtra_args.py", line 16, in <module>
print("C:",P.Carg)
AttributeError: 'CDPParameter' object has no attribute 'Carg'