Converting Kwargs Into Variables?
How do I convert kwargs objects into local variables? I am a math teacher and I want to write a helper function where I can use JS-style template strings to write problems. I want
Solution 1:
If you're planning to use eval
, you don't need to convert them to locals at all. eval
takes optional globals
and/or locals
arguments that defines the active scope variables for that expression. If you provide globals
(the second positional argument) and not locals
(the third), then globals
is reused as locals
, so for example:
>>> eval('a * b', {'a': 5, 'b': 3})
15
Post a Comment for "Converting Kwargs Into Variables?"