Author

Bob Belderbos Avatar

Bob Belderbos

Latest articles

by

  • This article appeared first as a Pybites email. To receive this kind of content first, subscribe to our weekly newsletter. For a long time, I thought I should not make mistakes when teaching other developers. I would hide behind slides because they were “hardcoded”, safe, or I’d do a lot of editing of my coding videos, they had to be “perfect”, right? Live code, heck no, not me! But I was wrong! About a year ago I pivoted and now I teach a lot by live coding (in group setting I mean; I already did this consistently and successfully with…


  • ,

    Reflections on the Zen of Python

    ·

    ·

    5 min read

    An initial version of this article appeared as a Pybites email first. If you like it join our friends list to get our valuable Python, developer and mindset content first … How following the Zen of Python will make your code better, a lot better. This epic set of axioms (triggered by typing import this in the Python REPL) says a lot about code quality and good software design principles. Although each one is profound, let’s look at a few in particular: Explicit is better than implicit. This is an important one. If we don’t state things explicitly we miss obvious facts…


  • ,

    Building a 500 line API regression test suite

    ·

    ·

    4 min read

    This article appeared as a Pybites email first. If you like it consider joining our friends list for weekly Python, developer and (!) mindset content … Last year I built a cool API to post code images using our pybites-carbon tool. It will store the tip code in a database and store the code image in an S3 bucket. A few weeks ago I finally made it open source so I am happy to receive contributions etc. 🎉 I am not sure why I kept it private for so long but one reason was a much needed cleanup 😅🤯 OK some lines are black formatting, but…


  • ,

    5 ways I use GitHub Actions

    ·

    ·

    3 min read

    I am increasingly using GitHub Actions these days. If you’re new to this you might want to check out our article or video. In this article I will show you 5 cool ways I use it day to day. Run tests and linters The first and most obvious reason is to automate tooling. Although you probably want to first and foremost do this step locally, for example by using pre-commit, it’s nice to always have that second automated check in the cloud. Example workflow. On: push dictates that I want to run this job upon every code push. You can read the steps…


  • , ,

    How to create a self updating GitHub Readme

    ·

    ·

    2 min read

    It was about time to give my GitHub profile a nice intro so inspired by Simon Willison’s blog post I decided to make an intro Readme that auto-updates. First I made a GitHub repo called bbelderbos, my username. That’s how it works: GitHub defaults to showing the Readme.md of your username’s repo on your profile page. Now the auto-updating part: Looks nice no? Some other things I learned: I hope this inspires you to not only make a “Hi there” Readme yourself, but also to try to keep it updated by pulling in other data sources that are relevant for you…


  • Finding new and removed Python 3.11 modules in 8 lines of code

    ·

    ·

    2 min read

    In our TIL Slack channel AJ shared a cool new find: Today I learned about sys.stdlib_module_names: a frozenset of strings containing the names of standard library modules. … AJ on the Pybites Slack – TIL (today-I-learned) channel So I thought to give it a little test drive, specifically checking for modules that were added and removed in Python 3.11. This is what I did: I used the pickle module to persist the frozenset that sys.stdlib_module_names returned beyond the 3.10 REPL session. Next I went into the 3.11 REPL and loaded it back into the mods_310 variable using pickle.load(). And lastly,…


  • ,

    Tips for clean code in Python

    ·

    ·

    5 min read

    In this article I will give you 10 tips for cleaner code. Hope this helps improve your Python code. 1. Smaller units. Break long functions (methods) into multiple smaller ones that do one thing (SRP or “Single-responsibility principle”). This will make your code more modular and easier to test. For example, a function that parses a csv file, builds up a result list and prints the results does 3 things and should be split accordingly. For more about writing better functions in Python, see this article. Update: a great addition by Michael Kennedy is to watch for comments in long…


  • Single or double quotes in Python?

    ·

    ·

    3 min read

    Whatever you think about Twitter these days, it’s pretty handy for us developers to ask questions and get inputs 💡 Last week I asked about single vs double quotes in Python: I thought double quotes were a given, black – “The Uncompromising Code Formatter”, defaults to them and I personally find them pleasant to the eye. Until I read about a different formatter in Fluent Python (2nd ed) called blue (“a somewhat less uncompromising code formatter than black”) and its preference for single quotes: Given the goal of enforcing a “standard” coding style, blue is better than black because it follows…


  • ,

    A super simple Zettelkasten note taking system

    ·

    ·

    3 min read

    Yesterday I found this amazing gist that got me running with Zettelkasten in no time 💪 Check out this short YouTube video where the author demos this workflow: As the Zen of Python wisely taught us: Simple is better than complex – and this is so true for what can easily be an overwhelming task of putting a note taking system in place, specially the Zettelkasten. In case you’re not familiar with Zettelkasten, read up on it here – definition quote: A Zettelkasten is a personal tool for thinking and writing. It has hypertextual features to make a web of…


  • ,

    Making plots in your terminal with plotext

    ·

    ·

    2 min read

    In this blog post a quick script to plot the frequency of our blog articles in the terminal. It’s good to see that we’re getting back on track 🙂 The code gist is here. First we import the libraries we are going to use. As always we separate Standard Library modules from 3rd party ones as per PEP8: Then I define some constants: I defined a year month generator. Why? Because some months we have not posted, yet I still want to show them on the graph. Then the wokhorse function that calculates the amount of posts per month. We…