9.09.2005

Python

I'm finally starting to do some real work in Python. There are some small annoyances, like the weird nodelimiterlowercase built-in names, but generators are (a carryover from Icon, I believe) are terrifically useful. I'm surprised something like them didn't show up in other scripting languages earlier, since they're naturally suited to the sort of source/filter/sink piping you see often in scripts.

In this particular case, I'm using a generator to produce specification objects one at a time from Perforce, which conveniently gives you an option to get your command results in the form of marshalled Python objects. Generators let me open up one connection to Perforce for a whole set of these, and return them one at a time as requested. The generator "owns" the network connection, and keeps it up while waiting for future requests. Poor man's lazy evaluation!

No comments: