Andrew Channels Dexter Pinion

Wherein I write some stuff that you may like to read. Or not, its up to you really.

September 29, 2005

Java or Python libraries in Jython?

I've been writing some more Jython code recently. In particular I've been quite enjoying the combination of both language's standard libraries. The ability to mix and match is saving me a lot of work.

Except where it doesn't of course. There is an inevitable overlap between the two standard libraries which leads me to the question - which should I use?

An example from my current code, I want to include the current date (in the format YYYY.MM.DD) in certain file names. I can get this using the Java standard library;

from java.util import Date
from java.text import SimpleDateFormat

df = SimpleDateFormat('yyyy.MM.dd')
today = df.format(Date())

Or I can use the Python library;

from time import strftime, localtime
today = strftime('%Y.%m.%d', localtime())

I suspect the Java version will be marginally faster as that's the language everything ends up running in, but the purist in me wants these scripts to be as close to pure Python code as possible.

Does anyone have an opinion on this?

Posted by Andy Todd at 03:51 PM | Comments (6)

Dangerous Combinations

According to this gamespy preview two of my favourite computer related things come together in the new Civilization 4 game. Civilization the game and Python the programming language.

If what they are saying is correct you will be able to change the game with triggers and scripts written in Python. It even looks like the AI SDK will allow you change more fundamental game play aspects and create what will be in essence a whole new game.

There goes my productivity and free time for the rest of the year.

Posted by Andy Todd at 02:28 PM | Comments (4)

September 21, 2005

OSDC 2005

My proposal to give a presentation at the Open Source Developer's Conference 2005 has been accepted.

I'll be giving a thirty minute high level overview of PythonCard which will mainly be a hands on demonstration. The difference between this conference and others I have presented at is that I've got to write a paper for this one.

The good news here is that because my presentation is going to be a demonstration there's no danger of me writing a document and then just standing up and reading it aloud. What I'll hopefully get round to doing (work project pressures permitting) is writing a two or three page history and description of the project. People can read this before or after the conference and it will stand on it's own two feet (and hopefully be good enough to go on the project web site). The live session then will concentrate on demonstrating the fruits of this work.

Having never done this before is this a good thing? I'm going to use four or five slides in my presentation anyway, but I thought that writing an actual paper as well would be more useful than just submitting the text of my slides.

As ever, suggestions of what to include (or exclude) are very welcome.

Posted by Andy Todd at 05:58 PM | Comments (4)

September 05, 2005

Checking my file copies

I spent a fair part of the weekend rearranging the digital photo files on my hard drive. I moved from a single folder to a nice nested structure which organises the pictures by date. Before I delete the files from the original folder I wanted to ensure that I'd copied every one. So I wrote some code. Which I now present with a small request, how could I have done this better?

By which I mean, more elegantly, efficiently or more readably, with the only constraint being that I'm not going to change the language it's written in. Answers in the comments please.

def check(directoryA, directoryB):
     "Check that every file in directoryA is present somewhere under directoryB"
     filelist = Set()
     for dirpath, dirname, filenames in os.walk(directoryB):
         for file in filenames:
    missing = []
    for file in os.listdir(directoryA):
        # find file under directoryB
         if not file.startswith('.') and file not in filelist:
             # print "%s is missing" % file
    return missing

Posted by Andy Todd at 07:17 PM | Comments (8)