Topic Archive

Concepts

  • What The Heck Is Yield For?

    ·

    ·

    5 min read

    A question came up recently about the purpose of the Python yield expression and when you should use it. Consider this silly function that computes a list of integers from 0 to 99 raised to the given exponent: When called, this function runs thru all 100 integers in the range computing each term and then returns the list to the caller. We can sum the list and get the expected result. This function will return to the caller pretty quickly, however when the number of items being processed grows much larger, say two billion, then the delay between calling the function and…


  • Introduction I recently re-engaged with one of my open source projects and it was a rewarding experience. 🎉 It was a Pybites project I had written the core for years ago, but thanks to some amazing Pythonistas in our community it became a way more mature tool so I had to get acquainted again. I was resolving an issue that had been causing some disturbance in our community, hence fixing it was quite satisfying. Contributing to open source is amazing, and with the amount of projects out there your contributions are necessary. It’s also one of the best way to…


  • Anyone who’s worked with Python knows that modules can be a Godsend, saving you time, effort, and many lines of code. They even have namespacing built-in 💪 😍 To expand on this a bit: However, not all ways of using modules are equally beneficial. In this article, we will discuss why using import * can be more problematic than it’s worth, and what you should do instead. Why is this a problem? When you use import *, Python brings in every single function and variable from the other module into your own. This can cause something called “namespace pollution” 😱…


  • In this new podcast episode we are excited to have Chris May back to delve deeper into the intricacies of refactoring. Watch here: Listen here: We talk about the significance of the Flocking Rules, a set of guidelines derived from “99 Bottles of OOP” by Sandi Metz and Katrina Owen.  These rules provide developers with a systematic approach to refine their code by focusing on recognizing similarities, identifying minimal differences, and making straightforward changes.  We also talk about the importance of taking small, incremental steps in refactoring, ensuring code health while mitigating the risks of accumulating technical debt. We reference…


  • Python allows you to use *args and **kwargs in function definitions to accept an arbitrary number of positional and keyword arguments, respectively. Here is a simple example: Different types of function arguments In the above example, the arbitrary_args function is defined to accept any number of positional and keyword arguments using the *args and **kwargs syntax. When the function is called with arbitrary_args(1, 2, 3, a=”apple”, b=”banana”), the *args collects all the positional arguments (1, 2, 3) into a tuple, and **kwargs gathers the keyword arguments (a and b) into a dictionary. Consequently, the function prints the tuple (1, 2,…


  • When you start a bigger software project it’s very beneficial (and necessary) to make a mind map first! It helps planning, organizing, and executing the project. Here are 6 advantages of mind mapping: Here is an example of one we did for our coding platform: CodeChalleng.es: Mind mapping your idea helps foster a well-structured, organized, and efficient development process, leading to a higher likelihood of project success 💪 Hence why we always start with this step when we build a new project / product ourselves or with our clients in our PDM coaching program 🔥 Get started here with our…


  • Feel Comfortable with Git?

    ·

    ·

    10 min read

    Folks come to me to ask for help with Git. Sometimes they can’t guess what git subcommand they need. (Git 2.37 has 169.) Sometimes they know what subcommand they want, but don’t know what flags to use. (git log now has 149 flags and options.) Sometimes they issued a command, and Git didn’t do what they expected 😱 Maybe you’ve had one of those problems yourself. Typically, their problem isn’t Git. They even want Git to do something that it can do, easily. They’re just asking Git for it the wrong way 🤯 Usually these folks just have the wrong…


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


  • I have learned a lot over the past 2.5 years of my Python journey. What started out as a hobby during COVID-19 lock downs in 2020, has now become a major component of my professional workload. This article is designed to highlight the importance of the iterative process: write some code -> learn new stuff -> review some code -> refactor. I will share some code I wrote in April and May of 2020 (approximately two months into learning Python), my thought process at the time, how I decided to refactor it, and finally a performance comparison. One crucial factor…


  • I was asked to help parse a JSON file that is delivered by the iTunes Store Customer Reviews API JSON endpoint. It is not so important how this API works or if there are better APIs for this. Instead, let’s assume that we found our favorite API to work with and that our request makes perfect sense and now we have to deal with the API’s response, JSON in this case. This article will guide you through the necessary steps to parse this JSON response into a pandas DataFrame. I will focus heavily on the concepts and code development and…