Xmas decoration, part 2
If you tried the code from our intro on decorator, you may have noticed big shortcomings. That's because it was a bird view, but there are details to iron out.
Python tutorials, tips, and insights for developers.
If you tried the code from our intro on decorator, you may have noticed big shortcomings. That's because it was a bird view, but there are details to iron out.
The best CPython commit of 2023
Every Python dev will go through the moment where they need to learn about those damn @decorator.
Functions and classes are objects in Python. You can assign them to variables, pass them as parameters and return them from function calls.
Some devs are 10x. Some people are talented designers. Some are capable of staring at the screen for 10 hours in a row.
This article contains nothing new. In fact, those things have been talked about everywhere on the internet for the last 15 years. Yet, I still see them in the wild, so I decided to add one more reminder.
A proposal to encourage the use of named args
(This article is so short there is no summary)
Django, not Flask, is the better choice for beginners' first serious web development projects.
Since the last article, the product works, and often that’s all we need. But if you want to make it feel nice, you can use animations and client side scripting for a better UX.
Toward adding iOS as a supported platform
In this part 4, we will fix the issues identified in part 3:
The to-do works, so we are going to break it. Because that's what devs do, they touch working code to make it better and introduce bugs in the process.
We have a to-do list app, it's simple and it works. It even has some Ajax magic to not reload the whole page.
Since the entire Web has voted for to-do lists to be the canonical frontend toy example, this is what we are going to do.
Use HTTP 303 for redirections.
Performances are underwhelming
Python developer survey 2022
There are some formatting you will do over and over again, and not having to think to produce them, making sure you can continue your code without interruption, is going to produce a far better experience.
There is nothing HTMX does that you couldn't do in another way. But HTMX pairs wonderfully with traditional server side frameworks and gives you clean, correct, results quite fast. You won't get candy crush bling level with it, but you will get...
The analogy of putting things in a box that works for most languages to explain variables doesn't fit Python very well. Python variables are quite dumb: they have no type, no permission, they are barely stickers you put on objects, like the ones...
Many geeks and nerds believe they are more intellectual than emotional. I beg to differ. They are very much driven by their emotions, and one of the consequences of this is how much they lie about how easy things are.
Concurrency and parallelism are hard, plus Python could do better in that regard.
Classic situation: you have leveled up, now you can use better gear.
When you work for a small entity, or a bigger but one with a strong culture of employee empowerment, everything is fluid.
Microsoft announces Python support in Excel
The call for donations grinds many people's gear. It's obnoxious, and hides the real Wikipedia financial situation. Between the truth manipulation, ChatGPT parsing, and the drastic editor rules that make contributing hard, finding reasons to help...
Sometimes you want to sort, and sometimes you just want things to stay sorted. For the latter, we can use heapq to create a queue that guarantees to pop each element in order, bisect to manually insert at the right place, or sortedcontainers, to...
Concurrency has a lot to do with sharing one resource, and Python has dedicated tools to deal with that depending on the resource you must share.
At the beginning of a dev career, you focus on improving your technical skills, which is perfectly natural. But people don't pay for code, they pay for solutions to problems.
Sorting any iterable in Python can be done with sorted(), which will always return a new list without modifying the original object.
After the articles on context managers and iteration we can now explore a new pattern.
Now that you are comfy with iteration, let’s see how to:
Python without the GIL, for good
Python is slow, but the community compensates by using fast compiled extensions like the numpy-based ecosystem, including pandas and scipy.
You can create a very peculiar object using parenthesis on a comprehension:
Python iteration is made simple thanks to the inclusion of the iterator design pattern, available through the for loop:
Creating a custom context manager takes little time and increases code quality, even if you use it only once.
In order to explain the use case of mixing a context manager and an iterator, I will spend the next few articles introducing each concept.
What could be easier than doing an HTTP POST?
While there are various ways of making a script configurable in Python, argparse is a very popular option. Unfortunately, it's also a cryptic one.
Python 3.7 reaches EOL, the egg format is deprecated
When people say "Python", they usually mean CPython, the reference Python implementation. But there are others, oh, so many others:
My first hype exposure was "use the Extensible Markup Language for everything". Learning from it allowed me to live through the front end stack explosion, the micro-service overdose and many, many more silly trends.
If you code long enough with any language, there are things you will eventually wish to tweak. As of 2023, those are mine:
Instead of having to limit sanity checks to the boundaries of the program, we could re-use those as function contracts using the assert keyword. Indeed, setting PYTHONOPTIMIZE removes all assert, making the check useful in dev, and free in...
You can merge dict with dict.updates(), **, | and collections.ChainMap
f"{0xBE_AF:.2f}" is what happens if you use "_" in hex, and interpolate it with a 2 decimal precision.
There is not binary files on one side, and text files on the other. All files are binary, some of those binary files can be interpreted as text.
Once you ship your software, most of your end users will be better served by replacing the stack trace with some actionable error message in case of a crash.
Stack traces are your friends. Just remember to:
Massive wave of deprecation coming due in the stdlib
Just a quick heads up, I’m moving the newsletter to its own custom domain name.
You can take a simple function such as:
Python shells are incredibly useful, but every time your start one, you tend to repeat the same things over and over.
Environment variables are variables that can be set from outside a program and read from inside a program. They are very useful, but more and more devs don't know how they work. Hence this article.
I'm at this point in my career where whatever new project I start, I usually have an old project I can copy for the baseline.
PDB is an ugly but convenient debugger that is always available with Python.
I bookmark a lot, so I wish Web browsers would save some bookmarked pages entirely on disk.
String interpolation
Most new Python projects are still about AI
Understanding Python imports will make you a happier coder.
UPDATE: if you don’t need a full build system but rather only a task runner, just is what I would recommend over Doit nowadays. However, Doit is still a good option if you need a DAG with dependency checks or if having something in Python is...
Python programming will be much easier once you have a minimal understanding on how to use the terminal (the black box), the shell (the program the black box displays) and the prompt (the way the shell tells you it's your turn).
Most devs are average, but many strong opinions in IT are shared by people who are better than average. Because of this, there is a gap between what most people need, and what they get told to do.
THIS ARTICLE WAS WRITTEN BEFORE UV CAME OUT.
UPDATE: THIS ARTICLE WAS WRITTEN BEFORE UV EXISTED. UV SOLVES MOST OF THOSE PROBLEMS. USE UV IF YOU CAN.
THIS ARTICLE WAS WRITTEN BEFORE UV EXISTED. UV IS CURRENTLY THE BEST WAY TO SETUP PYTHON. USE IT IF YOU CAN.
THIS ARTICLE WAS WRITTEN BEFORE UV EXISTED. UV SOLVES MOST OF THOSE PROBLEMS. YOU CAN TELL PEOPLE TO “SIMPLY” USE UV.
THERE IS NOW A MUCH BETTER WAY:
EDIT: the formula of the blog has changed a lot since then.