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 - Comprehending List Comprehensions

List comprehensions have been in Python since 2.6.x. If you're not using list comprehensions with Python, you are likely using a for statement and iterating through an iterable like this:

trees = 'oak', 'pecan', 'hickory', 'cherry'

for tree in trees:



You ...

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 - 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 - Namedtuples Examples

Namedtuples are tuples turned into convenient containers for simple tasks. The standard tuple will only have integer indexes for accessing individual members. For example:

>>> trees = ["pecan", "oak", "hickory"]

To access these individually, I would need to do:

>>> trees[1]

Namedtuples are tuples that allow you to access ...

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

How to Use Source Code Analyzer PyLint

Pylint is a Python source code analyzer that looks for programming errors, helps enforce coding standards and looks for bad smelling code.

Pylint has a lot of rules that are active out of the box. Still, you can configure which ones you don't need by editing a pylintrc file ...

Read More