Today I read some Python code and I asked myself "mmm what? How does it work? What's the meaning of raising an exception from another one? In this article I'll answer on: What is an exception?What is an exception chaining?Why is it important to use it?How to chain exceptions in Python? Let's get started! Introduction… Continue reading Exception Chaining In Python
Category: Python quirks
Structural Pattern Matching In Python
Once upon a time, Guido van Rossum, the Python creator, decided to reject a simple feature (PEP 3103): Switch case The reason for rejecting this PEP is: A quick poll during my keynote presentation at PyCon 2007 shows this proposal has no popular support. I therefore reject it.~ Guido van Rossum Lots of software developers… Continue reading Structural Pattern Matching In Python
Python Strings Prefixes
Strings are easy. kind of. Sometimes though, you can find one character right before the left apostrophe (or quotation mark). In this article, I'll explain the difference between the prefixes you can write there. There are four possible literals: u - unicodeb - byter - rawf - formatting Literals comparison Regular string string = 'Hello… Continue reading Python Strings Prefixes
The Python’s Disassembler
Recently, I've added the isnt keyword to the Python language grammar, but I used the same is not AST node. In this article, I'll demonstrate how to continue adding a new rule. The next things to do are building an AST node and compiling it to a Python byte-code. Creation First, we need to define… Continue reading The Python’s Disassembler
Is It Or Isn’t It?
The other day I wanted to check if a variable is not equal to a singleton (like None for example). In Python, when we compare singletons we would prefer to use is instead of == since the is keyword compares the addresses of the variables, while == compares the values. It's not a complicated task,… Continue reading Is It Or Isn’t It?
The New Python Parser
I forked the CPython repository almost 18 months ago. Recently, I wanted to add a new grammar rule to the Python language, so I started with rebasing the code against the original repository and... oh boy. I had so many merge conflicts. A few months ago a new parser was merged to the main branch. The new parser is written… Continue reading The New Python Parser
Python’s Super Duper Function
Object-oriented programming (OOP) is one of the popular programming paradigms we have today. In this post, we'll understand how super function works and why it's important. I assume you're familiar with the OOP paradigm. Thus, I don't explain it in this post. There are lots of good materials related to this subject. Let's dive into… Continue reading Python’s Super Duper Function
Running Another Process With Python
We have a Python software and now we want it to run a new process. How is it possible? In this post, I'll review the different ways to run another process in Python 3.8.2 running on Posix compatible operating system. There are two modules for our cause: os: provides a portable way of using operating… Continue reading Running Another Process With Python
Python Scheduler VS Timer
We have a function and we want to run it in X seconds. What should we do? The basic way is sleeping X seconds and executing the function: Did we run the function after X seconds? Yes, but what if we want our thread to continue doing something else? Also, what if we want to… Continue reading Python Scheduler VS Timer
Waiting For A Signal
Last week I found an interesting issue in my application. I noticed that my application cannot listen to signals. After debugging it a few days, I found out that it's related to the use of "threading.Event" in the main thread when waiting. side-note: I run python2.7 on Ubuntu 16. It was fixed in python3.6. As… Continue reading Waiting For A Signal