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:

PNG
The Definitive Guide
Greg Roelofs
O’Reilly 1999

pngbook-cover-1.jpg

Released under the GNU Free Documentation License, V1.1.
http://www.libpng.org/pub/png/book/

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:
http://en.wikipedia.org/wiki/Portable_Network_Graphics