eval - Can I use a string as a named argument in python -
this question has answer here:
- dynamic keyword arguments in python? 4 answers
i've got string form timedelta object based on value. write if statements, know string match 1 of named arguments timedelta object. want similar below:
td = timedelta("hours"=5)
or:
my_var = "days" td = timedelta(my_var=5)
what recommended way this?
use double-asterisk kwargs syntax:
td = timedelta(**{my_var: 5})
Comments
Post a Comment