Tuesday, January 26, 2021

Evaluate Expressions Dynamically With Python eval()

The built-in Python function eval() is used to evaluate Python expressions. You can pass a string containing Python, or a pre-compiled object into eval() and it will run the code and return the result.

Although Python’s eval() is an incredibly useful tool, the function has some important security implications that you should consider before using it. In this course, you’ll learn how eval() works and how to use it safely and effectively in your Python programs.

In this tutorial, you’ll learn:

  • How Python’s eval() works
  • How to use eval() to dynamically evaluate arbitrary string-based or compiled-code-based input
  • How eval() can make your code insecure and how to minimize the associated security risks

The code in this course was tested with Python 3.9.0, eval() has not changed much and older versions should be compatible.


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]



from Real Python
read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...