Hi, I'm Harlin and welcome to my blog. I write about Python, Alfresco and other cheesy comestibles.

Python - All Things Being Equal: "is" vs "=="

In the world of drink branding it is very important that all of your products of the same line of drinks taste exactly the same. Companies like Coca Cola, Pepsi, Budweiser and all the rest go through great lengths to make sure that their drinks taste exactly the same. This ...

Read More

Python - How to Use Underscores in Your Code

Note: This post was derived from Dan Bader's post on underscores that explains the subject in a lot more detail. If you are interested in reading his article, go here.

If you're a new Python programmer, you are likely encouraged to have a look at other programmer's ...

Read More

Python - PEP 8 Series - Whitespace

Python is one of the few languages out there which takes whitespace into consideration for the purpose of readabilty. This is why this code is more elegant and flowable as you type:

def add_and_double(num1, num2):
    addition = num1 + num2
    product = addition * 2
    return product


public int (int num1, int ...

Read More

Python - How to Group Imports

In case you were ever wondering, here is the standard way to group your imports.

# Standard library imports
import os
import sys

# 3rd party modules
from django.http import HttpResponseRedirect
from django.shortcuts import render

# My project-wide modules
from blog.settings import THEME
from lib.util import get_http_referer

# From separate ...

Read More

Python - PEP 8 Series - Indentation

Consistent indentation of code is key for Python as you can get some painful indentation errors. If you really want to avoid that problem all together, always use 4 spaces for indentation. Also, avoid tabs, you don't need them.

Keep your lines at 79 characters or less. Continue to ...

Read More

Python - Using @property and @setter for Data Encapsulation

I came to Python after coding in Java for a couple of years. That wasn't a very long to learn the ins and outs of Java or any other programming language but it was my first one where I had built up a measure of proficiency. When it comes ...

Read More

Python String Formatting - More than One Way to Do It

By now, you've probably seen one of the guiding principles of the Python programming language when running "import this" in your interpreter.

Python's mantra on ways to get things done in the languge has been: "There should be one-- and preferably only one --obvious way to do it ...

Read More

Python - Args! and Kwargs! How do I Use Them?

Have you ever looked at Python code that included *args and **kwargs and wondered what in the world these things are? Python is supposed to be quickly readable to someone either new to programming or someone coming from another programming language. These look weird. What gives?

Well, the *args and ...

Read More

Python - Basic Unit Testing and Test Driven Development

In case you're unfamiliar with it, code testing is proving your code works as expected. Unit testing does this too, of course, but in much smaller bites. There's also this other thing called Test Driven Development. There are also many other subjects that have to do with code ...

Read More

Python: How to Merge and Sort Dictionaries by Values

If you ever get two dictionaries that you would like to merge together, you can do so with the "**" operator. How does that work? The "**" operator takes a dictionary and extracts its contents and passes them as parameters to a function.

Consider that our person has some keys ...

Read More

Python: How to Make Use of Constants and Assertions

I knew there was no such thing built in to Python for one to create a constant but of course, I happened to find a hack by Alex Martelli here.

Copying verbatim and shamelessly, here it is:

# Put in const.py...:
class _const:
    class ConstError(TypeError): pass
    def __setattr__(self ...

Read More

Understanding Pythonic Truthiness and Noneness

I decided recently to pay for a class from Talk Python. I did this to better my skills in Python and to evaluate Michael Kennedy's Python courses. The subjects for his courses seem really interesting and if they pan out, I feel these could be very useful in getting ...

Read More