Archive for the 'Python' Category

Determining Python program behavior based on available imports

Python’s import statement is an executable statement like any other. This means it can be used to determine if a particular external module is available. If a module is not available for import, the program can either modify its behavior accordingly, or shut down in a graceful fashion. Continue reading ‘Determining Python program behavior based on available imports’

Visual Debuggers

A visual debugger is a like an addictive mental drug. It’s fascinating to look at, very helpful at times, and it can become a crutch. Just as with alcohol or other drugs, a little bit can be fun and help get you to where you want to be, but too much can derail you. Allow me to explain.

I do most of my development on Linux (OK, I actually do ALL of my development on Linux or something similar like Solaris or BSD–I don’t do Windows) in C, C++, or Python. When the need arises to be able to peer into the code and see what, exactly, is causing an annoying fault I use gdb or DDD (a GUI front-end for gdb) for C and C++. For Python I use tools like winpdb or Eclipse with the Python IDE plug-in.

Continue reading ‘Visual Debuggers’

Finally coming up for air…

Well, contrary to any rumors going around, I’m still alive and well.

My new book from O’Reilly, “Real World Instrumentation with Python,” is just about to hit the presses. It’s in the final review stage now, and after that all that’s left is to hand it to the press operator and warm up the binding machines. At over 575 pages, with 200+ illustrations (all done by yours truly), it’s been a boatload of work, and I really hope that folks find it useful. It should be out in a couple or three weeks, but you can preorder it from either O’Reilly or Amazon.

Writing a book turned out to be a lot more work than I had originally expected, but it’s done now and ready to make its big debut.

Perhaps I’ll find some time to start posting here again on a regular basis.

It’s been a while…

In case you were wondering, well, I didn’t fall off the face of the Earth. At least not yet.

I haven’t had a chance to post anything since the middle of August because I’ve been massively busy wrapping up a big project, writing a couple of book proposals and trying to work on some technical papers. Of course that means that I’m spending a lot of time putting out little fires, chasing down issues that seem to only pop up at the last minute, and not getting a whole lot of sleep.

Anyway, I’m just about ready to post the last two parts of the PGM series, but in the meantime I would like to direct the attention of the Python folks to the tool Epydoc. If you write more than just simple utility scripts in Python, then you really should take a look at this (if you haven’t already). It may not have all the bells and whistles that Doxygen has, but it has enough to make it very useful. At work I have a cron job set up on the lab server to run Epydoc across the code base every night and put the results up where folks can access them via the internal web server.

More (much more) to come. Stay tuned, film at eleven.

Netpbm and the PGM Format – Part 2

This is the second part of a series on processing PGM format image files in Python. For an overview of what PGM is refer to Part 1. In this part we’ll look at how a PGM file is generated and create a few small images to look at. In part 3 of this series we’ll examine some utility functions to write, read and display PGM image data. Lastly, in part 4, we’ll take a look at a case study of how the PGM format was used for scientific CCD camera testing, and offer some suggestions for how you might be able to use it.

Continue reading ‘Netpbm and the PGM Format – Part 2’

INI Files

So-called “INI” files are ubiquitous. You can find them on Unix systems, Windows platforms, and even in the flash memory of embedded systems. I even once wrote my own INI parser for some software on a embedded diskless VME control system running WindRiver’s VxWorks. It allowed us to upload new configuration and control parameters on-the-fly in a human-readable format. Very handy.

Continue reading ‘INI Files’

Free PNG Book Available On-Line

I recently stumbled across this whilst sifting through the Weird Wild Web:

The Definitive Guide
Greg Roelofs
O’Reilly 1999


Released under the GNU Free Documentation License, V1.1.

If you deal with image processing software then you really need to know about PNG. Superior to JPEG for images containing sharp edges and step gradients (i.e. line art and such), PNG uses a non-patented lossless data compression method. While it won’t compress down as much as JEPG, it also doesn’t suffer from high-frequency signal loss, generation loss and compression artifacts (checkerboarding and such). Also see the Wikipedia article on PNG:

Determining button up/down times in wxPython

I recently encountered a need to be able to determine how long a user held down a button on a GUI dialog in order to command a proportional amount of movement in a mechanism. In other words, the longer the button was down, the longer the mechanism would be commanded to move.

Continue reading ‘Determining button up/down times in wxPython’

Some Thoughts On Software Testing and Software Test Engineering

Software testing is an artform, and, make no mistake about it, a good software test engineer is an artist.

Software testing often gets a bad rap as being “dull”, “boring” or something that the goofy wonk down the hall does, but that the hotshot developers don’t bother themselves with. I used to view testing as an evil necessity as well, until I discovered how challenging it could be.

Continue reading ‘Some Thoughts On Software Testing and Software Test Engineering’

Building Better Device Interfaces

I recently encountered an interesting example how not to implement a control interface for an external device. The devices in question here are two laser products from the same company that do essentially the same thing. The problem is that the software for each of the controller units seems to have been developed in sealed rooms with little or no cross-communication between them. I’m not going to name any names, mainly because other than the command set silliness these are good products, but I’ve suffered enough at the hands of some unknown yahoo (or group of yahoos) that I felt compelled to write up a quick “lessons learned”. I will refer to these two products as controller A and controller B.

Continue reading ‘Building Better Device Interfaces’

Follow Crankycode on

Little Buddy

An awesome little friend

Jordi the Sheltie passed away in 2008 at the ripe old age of 14. He was the most awesome dog I've ever known.