How to execute arbitrary code in Python?

3

I use an xBase language that has macro replacement as in the original Clipper. Is there something equivalent in Python? We use a lot of command line assembly via menus at runtime. For example, making filters.

    
asked by anonymous 01.07.2016 / 14:28

1 answer

3

I have great experience with Clipper, I worked on the world's largest user of this language had privileged access to the language provider and was part of the developer group of Harbor, the Clipper replacement. I can tell you that if you used a macro, you used the language in the wrong way. You can do everything without it and it is always better to do so. In all languages this kind of thing is problematic and not recommended. As far as it would be interesting to use (I can only think of a case), the correct way is to do something more appropriate (even if it is more complex). It provides better solutions, even for the cases quoted in the question. Macro was a creation of dBase II because there was no programming language (even had * array) and this was the way to solve some things. DBase III has already provided better solutions to most of the issues without using macro. Clipper, especially 5, solved almost all other cases, and Harbor once killed the need for macro.

If you want to make the same mistake in Pyhton, eval() function is what demand. But I emphasize that it is insecure and unnecessary. Of course if you know what you're doing well, you can even use it. But it's complicated to use right. In general it's worth doing differently.

Related: Is Eval a Good Guy or Bandit?

    
01.07.2016 / 14:36