eval - Can I use a string as a named argument in python -


this question has answer here:

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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -