Exec() function in Python

bdmpoxbvc report abuse

Why shouldn't I use the exec() function? I heard from fellow students that this is a very bad practice, but I don’t understand why?

Answers

millykabvy report abuse

First of all, for security reasons. If you are executing something that you cannot predefine it means that you do not have full control over what your code does. It’s never good. Although you can follow some strict rules and make your code safe enough, there is almost always another way to do what you need. And this path will be easier to read and easier to debug, which is the second reason. And, of course, while you are looking for other implementations, you can get more useful Python skills for real applications. Even if you can achieve good results with exec or eval for your personal tasks, it should never be used in production for security reasons.

Add Answer

Need support?

Just drop us an email to ... Show more