All articles

  1. Python Packaging, the easy way

    This is an absolutely fantastic post on Hacker NEws, so much so I threw away the post I was working on for this exact same topic. All credit to the original author, I just formatted it.

    Packaging, the easy way

    Because I'm not on a blog, I can't go too …

  2. Python Tricks Roundup 2

    I subscribed to Dan Bader's mailing lists in January so you don't have to (you should though, it's decent). Here's the second set of tricks I got from it so far.

    Get the name of an object's class as a string:

    class MyClass: pass
    obj = MyClass()
    obj.__class__.__name__
    # 'MyClass …
  3. Python Tricks Roundup

    I subscribed to Dan Bader's mailing lists in January so you don't have to (you should though, it's decent). Here's the tricks I got from it so far.

    Python 3 has a std lib module for working with IP addresses:

    import ipaddress
    ipaddress.ip_address('192.168.1.2')
    # IPv4Address('192 …
  4. Notes on Functional Programming in Python

    Lambda Expressions

    Lambda expressions are simply small anonymous functions. I could go in to more detail, but I'd be hard pressed to beat Dan Bader's explanation linked at the end. Basically, you want to use them when you need a single expression that won't be needed elsewhere in your code …

  5. Notes on "Python's Class Development Toolkit"

    Adapted from a Jupyter notebook, these are my notes of the the Raymond Hettinger PyCon talk "Python's Class Development Toolkit", linked at the end.

    Include a Module DocString for your module

    '''Circuituous, LLC --
       An Advanced Circle Analytics Company
    '''
    

    Document your class and methods

    class Circle:
        'An advanced circle analytic toolkit …
  6. SoA and AoS, with Examples

    Structure of arrays (SoA) and Array of structures (AoS) are ways of structuring data to minimize CPU cache misses, speeding up data access and taking better advantage of processing power, especially in parallel programming. After minimizing the amount of data you are reading, writing, and copying, this is the next …

  7. MarkovBot Dev Diary #1

    Project Repository

    Unlike with Shelf, I didn't create a post for this project before I got started. It's been on the backburner for a while now due to time and frustration, but it's been living on in the back of my mind now since I did have fun working on …

  8. Composition in Python

    I'm a big fan of composition over inheritance in OOP, the only issue is that it's a bit harder to wrap your head around than basic inheritance. For a quick reminder, composition is simply aggregating objects together by making objects attributes of other objects. If an object has-a different object …

  9. Underscore in Python

    The underscore in Python has implicit (by convention) and explicit (enforced by the interpreter) meanings. While there might be more uses that I don't know of, I'll explain the five I do know.

    • Implicit
      • Single Leading Underscore: _var
      • Single Trailing Underscore: var_
      • Single Underscore: _
    • Explicit
      • Double Leading Underscore: __var …
  10. Shelf Dev Diary #1

    This is the first entry in a series of dev diaries on my latest and first serious project. This project is the culmination of my annoyance with having no good system to manage bookmarks, wishlists, reading lists, ebooks, and other media I want to consume across different systems. I'm constantly …

  11. Zero Padding Filenames

    I always hate when filename ordering gets screwed up because numbers aren't handled properly (1.txt, 10.txt, 2.txt, etc.), so the easy solution is to zero-pad the numbers. Renaming a bunch of files to add some zeros is no fun though, so here's some solutions.

    On Ubuntu, there's …

  12. Multiple Subprocess Calls Made Easy

    This is a very neat solution I figured out to calling subprocess on a bunch of commands easily with a loop.

    The key here is the split(), this will break down the command in to a list, which is the format subprocess needs, without manually formatting it. I use shlex …

  13. Python Decorators

    Decorators in Python were confusing when I first came across them, but the concept is simple enough and very powerful. Note that Python decorators are not to be confused with the design pattern of the same name. In Python, everything is an object and functions are first class citizens. Those …

  14. Python Learning List

    Recently a colleague asked me for Python recommendations and resources for learning. This is a tough question since the answer is different for everyone, but in general these are the resources I think are best or have helped me.

    Tools

    It's easy to get caught up learning new tools, frameworks …

  15. Python with Statement

    with, and by extension context managers, are one of the things about Python that I've used but never really understood. At my current job it's used quite frequently for an API I have to access, and I'm also trying to square where it fits in relation to decorators, so it's …

  16. Modern Strings in Python

    I'll be honest, when I first read about f-strings (aka formatted string literals) coming to Python, I was not impressed. The syntax looked pretty bad and it was creating yet another way to do the same thing, which goes against the Zen of Python. After going over it a bit …

  17. Reversing Strings in Python and PowerShell

    Reversing a string is super easy in Python and a little more complicated in PowerShell. Both of them have multiple ways to do it, all basically similar. The only trade-offs appear to be obvious: do you care about the overhead of a function call, line count, verbosity, etc. Personally, I'd …