I have an exec statement to set the formatting of two variables in python 3.6. Even though the code works fine, I need to change this due to compliance issue. Please let me know how it can be done differently.
My statement: exec("{}='{}'".format(item,s))
thanks in advance for your help.
Without knowing more:
locals()[item] = str(s)
will work for "simple" names (foo
, x
, etc.), but not for more complex assignments that your exec
approach could handle (e.g. instance.attr
)
In either case, "there must be a better way" to do what you're trying to do, but there's no context to help with that.