How to transform a text in identifier name?

1

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?

    
asked by anonymous 03.11.2017 / 12:20

1 answer

2

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.

    
03.11.2017 / 12:38