Monday, May 4, 2009

Adventures in Python

A couple days ago at work we realized we'd need a script to automate a process that is incredibly error prone and mind-numbingly boring. Naturally I volunteered for the task, seeing as it would give me a chance to try some new things and challenge myself to think outside the box. To create the script I decided to use Python, partially because I've used it before and wanted to get a refresher, and partially because there is a nice API library available to assist what I'm working on.

The project I'm working on is to automate some Perforce tasks, and thankfully there's an API plugin for Python (aptly named P4Python) to make interacting with a Perforce server a snap. This API has been very nice to work with, it allows me to do server queries for Perforce files and recieve the results as lists or dictionaries. In a previous project I did something very similar, however to get information from Perforce, I had to run a commandline query, direct the results into a file, then parse the file. It was very cumbersome and difficult to develop and debug.

Working with Python has been somewhat of a culture shock. I've spent most of my time working in strongly typed languages, so getting adjusted to Python's dynamic type language system has been weird. I will say, being able to simply create a new variable and not worry about type declaration or memory management is great for quick iteration and turnaround. One thing that keeps biting me though is indentation being used as block delimiters. Apparently my fingers love hitting the delete key without me realizing it, so I often get errors about a certain block of code not being indented correctly.

No comments:

Post a Comment