Skip to content

Files

Latest commit

 

History

History
28 lines (17 loc) · 706 Bytes

exec-used.md

File metadata and controls

28 lines (17 loc) · 706 Bytes

Pattern: Use of exec()

Issue: -

Description

The exec() statement is dangerous, hard to test, and hard to read. Avoid it, as much as possible. This is largely due to the fact that exec() enables you to dynamically execute arbitrary Python code which is stored in literal strings. Consider going back to the code to check if there is a clearer, more direct way to accomplish the task.

Example of incorrect code:

text = "print \"hello, and goodbye\""
exec text

Example of correct code:

def foo():
    print "hello, and goodbye"
    
foo()

Further Reading