Blog / Python

How to delete Python .pyc and .pyo files on Ubuntu 14.04

September 2, 2014

I just realized today that Ubuntu has a command called pyclean already installed by default that will recursively delete all .pyc and .pyo files.

For example, to recursively delete .pyc and .pyo files from the current working directory, you can do:

pyclean .

If you’re not on Ubuntu, you can run this command instead:

find . -name “*.pyc” -delete

Source

A Python function for flattening irregular list of lists

July 20, 2014

Here’s a nice short function for flattening irregular lists in Python that I found on Stackoverflow a few weeks back. It returns a generator so should work fine for very big lists.

def flatten_list(object_list):
    """
    Flattens a list of objects.
    """
    for element in object_list:
        if isinstance(element, collections.Iterable) and not \
                isinstance(element, basestring):
            for sublist in flatten_list(element):
                yield sublist
        else:
            yield element

I tested it with lists like the following and it did the job: …

Deploying your Django app with Fabric

January 25, 2014

I’ve been making quite a bit of improvements and changes to my Django app, GlucoseTracker, lately that the small amount of time I spent creating a deployment script using Fabric had already paid off.

Fabric is basically a library written in Python that lets you run commands on remote servers (works locally as well) via SSH. It’s very easy to use and can save you a lot of time. It eliminates the need to …

Launching a new Django project: GlucoseTracker

January 1, 2014

I finally launched a project I’ve been working on the last couple of months just in time for the new year. It’s a web application for tracking blood glucose levels using all open source software: Python, Django, Twitter Bootstrap 3, PostgreSQL, Nginx, Gunicorn, and a bunch of others.

I originally started this project over 2 years ago to teach myself how to use the Django web framework, but I lost interest at some point …