[Tutor] wrapping a command line tool

Tim Golden mail at timgolden.me.uk
Fri Dec 15 17:09:50 CET 2006

> I am using a command line tool that allows me to specify a serial
> port and either read from or write data to it. I would like to create
> a python module that wraps that functionality and allows me to
> manipulate the incoming data to present it in a table for instance
> (like top works) or maybe store it in a dictionary and drop it into a
> database at timed intervals.

Simplest (though not necessarily the most modern) way:

import os

data = os.popen ("do_thing.exe param1 param2").read ()

# Do stuff with results according to need

Obviously how to format as a table depends
largely on what the data looks like and what
your intended display medium is. (PDF? HTML?


More information about the Tutor mailing list