Topic Archive

Modules

  • What is this pattern about? The Pipeline design pattern (also known as Chain of Command pattern) is a flexible way to handle a sequence of actions, where each handler in the chain processes the input data and passes it to the next handler. This pattern is commonly used in scenarios involving data processing, web scraping, or middleware systems. In this blog post, I’ll walk you through a specific example that leverages Python’s powerful functools.reduce and partial functions, along with the BeautifulSoup library for parsing HTML content. This code showcases the Pipeline pattern applied to HTML table extraction and processing. What…


  • Don’t waste you time in early optimization, stay focused on the product! Have you ever had a brilliant idea but hesitated to invest time and resources into building a full-fledged product? The fear of wasting resources on an untested concept is a common struggle for entrepreneurs and innovators. Fortunately, there’s a game-changer in the world of rapid prototyping: Streamlit. In this article, we’ll walk you through the process of turning your concept into a Minimum Viable Product (MVP) with few lines of code using Streamlit. By the end, you’ll have a functional prototype that can be shared and tested with…


  • In this article let’s look at the functools Standard Library module and 6 cool things you can do with it (be warned, a lot of decorators are coming your way! 😍) … 1. Cache (“memoize”) things You can use the @cache decorator (formerly called @lru_cache) as a “simple lightweight unbounded function cache”. The classic example is calculating a Fibonacci series where the intermediate results are cached, speeding up the calculation significantly: On my system this code takes 0.02s to complete. 😎 However if I comment the @cache decorator it takes 28.30s because of all the repeated calculations! 😱 Hence caching is…


  • This was a Pybites email first. To always get the latest and greatest content, subscribe here. Lately I have been learning some new libraries for weekly PDM Code Clinic demo sessions (e.g. PyScript, Flet, PySimpleGUI, Playwright, htmx, Redis, Leaflet, etc.) There is a general approach I take that makes this less painful and more fun. Of course having done development for quite a while makes things easier, but even after years of experience this craft does not come easy per se. The following tips are still generic enough that they help developers of all levels. Let’s also time the steps…


  • 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,…


  • 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…


  • The other day I wanted to get serious with the awesome Rich library. As we always say: you have to build to really learn + need ideas? Scratch your own itch. If you’re struggling for ideas, see what takes you long and/or is cumbersome and see if it’s a good candidate to automate it with code. Here is a more elaborate email we sent about this a while ago. Well, I had an itch for a while … I was always Googling color hex codes when styling web apps. What if I could do this from the command line? And…


  • My name is Russell Helmstedter. I am a middle school math and computer science teacher at De Anza Academy of Technology & the Arts (DATA). My first exposure to Python was in March of 2020. For some reason, I was stuck at home and couldn’t go out and do things. I decided to learn how to code. After googling things like “what coding language should I learn” and “learn how to code”, I found Al Sweigart’s Automate the Boring Stuff. I was hooked. I began learning everything I could about Python. I started listening to podcasts, reading blogs, searching for…


  • In this article I will show you how to make a beautiful yet simple graph using Django + Chart.js.  The code for this project is here. Getting the data We are going to plot the number of Bite exercises that get completed per month on our platform.  For this I exported the live data from the corresponding table in our database using this handy Postgres command: This will export the content of the table to a csv file. Setting up Django Next we will make a Django project and app so we can share it with this post: Note the…