Setting up the settings module in Django can be cumbersome for beginners. This module holds many properties that are vital to your application, and a minor error may be fatal. Moreover, you need to keep track of separate environments, such as local, dev, test, staging, production, and so on. In this short article, I will show you my approach to handling different environments in Django projects.
read more “Easy Configuration Management in Django Projects”Category: python
How to write a simple math interpreter in Python
Not long ago, I had to write a certain feature for my project. It involved parsing a mathematical expression from plaintext and evaluating it. This feature had to work with basic numerical expressions like 2 + 3
, support context to use variables: apples + 2 * oranges
, and parentheses: (2 + 3) - apples
.
The obvious (and least appropriate) solution was to use eval
. This standard function takes a string and runs it, treating it like Python code. This is considered to be very unsafe: eval
an execute arbitrary code, which makes it a potential security risk, especially if the input comes from untrusted sources. Malicious users could inject harmful code that could lead to unintended consequences, such as executing system commands or accessing sensitive information.
In this article, I will walk you through my safe and extensible implementation using Python’s ast
module.
A hands-on guide to concurrency in Python with asyncio
Many of us have experienced slow websites and laggy apps at least once while programming. These issues are inherent to the design of the systems we use each day: some operations take a (relatively) long time to complete. Transferring bytes over thousands of kilometres between you and the server, reading tiny magnetic fields on the spinning disk, and other such activities may take a moment. However, while your system is waiting for these resources it is essential to remain usable and responsive, and not waste precious CPU cycles. The concepts of concurrency and asynchronous programming were introduced to address these concerns.
read more “A hands-on guide to concurrency in Python with asyncio”Structural Pattern Matching in Python: In-Depth Review
Python is a multipurpose language, beloved by data scientists and full stack engineers alike. It promotes clear and concise code, thanks to its syntactic sugarness and philosophy. In this article, I will explain in depth how the most anticipated Python feature works: structural pattern matching.
read more “Structural Pattern Matching in Python: In-Depth Review”New Python 3.10 Features You Must Try Out
Python is beloved by many data scientists and general-purpose developers for its simplicity and elegance. The latest version of Python, the 3.10 is currently in beta phase, but no new features will be added ahead of its final release in October of 2021. Now is just the time to learn about its new features ahead of schedule.
read more “New Python 3.10 Features You Must Try Out”Unit-testing in Python: If You Do Not Test Your Code, No One Will
Python is a multi-purpose language that is used for everything backend. In this article, I will teach you to perform basic unit testing in Python, how to mock modules, and make sure your code is clean.
read more “Unit-testing in Python: If You Do Not Test Your Code, No One Will”10 Advanced Python Interview Questions
With Python becoming more and more popular lately, many of you are probably undergoing technical interviews dealing with Python right now. In this post, I will list 10 advanced Python interview questions and answers.
read more “10 Advanced Python Interview Questions”Python Context Managers in Depth
Python is a particularly clean and sugary language, thanks to its many convenience features. In this post I will go into context managers in Python, how to use them, where to find them, and how to write your own ones.
read more “Python Context Managers in Depth”Why Do You Need Decorators in Your Python Code
Python is praised for its clarity and syntactic sugariness. In this article, I will teach you to use decorators in Python to make your code readable and clean.
read more “Why Do You Need Decorators in Your Python Code”Why Python Written In Python is Faster Than Regular Python
Let’s be honest: Python is slow. When I say Python, I mean CPython, it’s reference, C-based, implementation. This is where PyPy comes into play. This is a Python runtime, written in Python (!), which performs 4.4 times faster than CPython. How? Read ahead.
read more “Why Python Written In Python is Faster Than Regular Python”