Blog / Python

Python script for auto-renaming your image files

January 19, 2012

I like to rename my pictures a certain way as soon as I import them to my computer. I usually follow this format: description_datetaken_3digitnumbering.jpg

I was using Metamorphose to do this for a while. But one time I wanted to rename my pictures while I was in New Zealand and realized I didn’t have the application installed on my netbook. I didn’t want to pay the $5 for the Internet access so I decided to …

Errors when installing the Python ‘lxml’ library using pip on Ubuntu

August 28, 2011

I thought I’d post this here, this is the second time I ran into this issue on Ubuntu and forgot what I did the first time.

If you get errors about things missing when you do ‘sudo pip install lxml’ on Ubuntu, you’ll probably need to install the following development packages (source):

  • sudo apt-get install python-dev
  • sudo apt-get install libxml2-dev
  • sudo apt-get install libxslt1-dev

You may also want to do ‘sudo pip …

How to configure the ‘logging’ module using dictionaries in Python 2.6

August 21, 2011

The logging.config module was updated in Python 2.7 and included a function called dictConfig() which takes a dictionary as an argument used to configure the logging module.

I wanted to use this in my new project so I can keep all my configurations/settings in one Python file but we’re not ready to upgrade to Python 2.7 just yet. The good news is you can just get the dictconfig module on its own and add it …

How to convert a string to a dictionary in Python

August 9, 2011

I just found out about this today while working on a Django app. I have some data stored in a database as a string but the structure is a dictionary and I wanted to retrieve it as a dictionary object.

Instead of parsing this data to retrieve the keys and values myself, it turned out Python has a module called ast (Abstract Syntax Trees) that can take care of this, specifically the literal_eval()function:

>>> …

GWT, Django, and JSON (with padding)

August 8, 2011

A couple of months ago I was working on a project where I needed to retrieve data in JSON format from a web service written in Python (using the Django web framework) under GWT. The data is then loaded into GXT/Ext GWT grids and charts.

After looking at a GXT example of loading JSON data to a grid, I thought this would be pretty straightforward, but of course I was wrong. Since the Django …