Knowing how to handle files in your programming language of choice is an essential skill for any developer. After reading this post you should be comfortable doing file operations in Python.
Python is a great language for writing command line scripts. When you need to run long running processes it is polite to indicate the overall progress to your user. You don’t want the user to think that your script has hanged and terminate the execution after a minute. Luckily, adding a progress indicator is really easy!
Historically, the Python syntax hasn’t had a switch-case statement. In 2006 Guido van Rossum, the original author of Python, proposed different alternatives for the switch-case syntax in PEP 3103 but they all seemed to have some problems and the idea didn’t gain enough popular support. The proposal was therefore rejected. Python version 3.10 changes this.
When you need to return complex data from a function you typically think of two options:
- put the values in a dictionary
- create a new object/class
The first option is simple to implement but you need to access the individual values by their keys. The second option allows you to access data via attributes and do custom calculations behind the scenes, but then you need to implement yet another class.
Is there something in Python that could give us easy attribute access without having to bother with custom classes?
GitHub Actions gives you lots of freedom to define custom workflows by combining different actions and running command line programs. Sometimes you might want to run small snippets of code, and that is already possible by running scripts from the command line with the
run keyword. What if you could write your Python script inside the workflow YAML file instead?
When you define an object in Python you usually give it some attributes that hold the necessary pieces of information in a place that makes sense. However, Python does not limit the use of attributes to the set that were described at object creation time.
Can you chain comparison operations in Python? Yes you can, each comparison is evaluated pairwise so you can chain together as many of them you want.
It can be easy to forget to use basic features like this if you come from a language that doesn’t support chained comparisons or if you’ve never seen them used in the wild. I’ve been using Python professionally for years but I have to admit that I still didn’t really know about this feature until recently.
You want to be a Python backend developer but have no idea what you should learn? Choosing what to focus on can be difficult. In this blog post I hope to help you by discussing different types of backends and the technologies that you could use to build them.
Building URLs is really common in applications and APIs because most of the applications tend to be pretty interconnected. But how should we do it in Python? Here’s my take on the subject.
It is quite easy to recommend your most popular posts to your readers if you are running a WordPress site. What if you are using a static site generator such as Hugo instead? On this post you’ll learn how to add a popular posts section by using data from Google Analytics, and how to automate the whole process.