I would like to be able to receive a string as a parameter and use it as the identifier name, to create a variable or function with that name (not to use as a dictionary key). Is it possible to do this?
I would like to be able to receive a string as a parameter and use it as the identifier name, to create a variable or function with that name (not to use as a dictionary key). Is it possible to do this?
It is possible. You need to know eval()
, exec()
and compile()
, but do not make such a mistake.
Always have a better solution unless you want to execute an externally entered code, which is still the wrong resource for this, but it is a way to solve, even though it is still a gambiarra. >
Even the dictionary is usually gambiarra in most cases, although it would be a slightly better solution and solve the problem.