|I l@ve RuBoard|
With limited space, we could cover only a few of the most popular frameworks currently used with Python. There are several others, which are also deserving of mention and which might very well be what you need. We briefly describe some here.
The Python Imaging Library is an extensive framework written by Fredrik Lundh for creating, manipulating, converting, and saving bitmapped images in a variety of formats (such as GIF, JPEG, and PNG). It has interfaces to Tk and Pythonwin, so that one can use either Tk widgets or Pythonwin code to display PIL-generated images. Alternatively, the images can be saved to disk in a variety of formats. The home for PIL is at http://www.pythonware.com.
Numeric Python is a set of extensions to Python designed to manipulate large arrays of numbers quickly and elegantly. It was written by Jim Hugunin (JPython's author), with the support of the subscribers to the Matrix-SIG (more on SIGs in Appendix A). Since Jim started work on JPython, the responsibility for Numeric Python has been taken over by folks at the Lawrence Livermore National Laboratory. NumPy is a remarkably powerful tool for scientists and engineers, and as such is close to the heart of one of these authors. More information on it is available at the main Python web site's topic guide for scientific computing (http://www.python.org/topics/scicomp/ ).
Here's an example of typical NumPy code, numpytest.py, and one representation of the data in generates:
from Numeric import * coords = arange(-6, 6, .02) # create a range of coordinates xs = sin(coords) # take the sine of all of the x's ys = cos(coords)*exp(-coords*coords/18.0) # take a complex function of the y's zx = xs * ys[:,NewAxis] # multiply the x row with the y column
If you remember your math, you might figure out that xs is an array of the sines of the numbers between -6 and 6, and ys is an array of the cosines of those same numbers scaled by an exponential function centered at 0. zs is simply the outer product of those two arrays of numbers. If you're curious as to what that might look like, you could convert the array zs into an image (with the aforementioned PIL, for example) and obtain the image shown in Figure 10.7.
NumPy lets you manipulate very large arrays of numbers very efficiently. The preceding code runs orders of magnitude faster than comparable code using large lists of numbers and uses a fraction of the memory. Many Python users never have to deal with these kinds of issues, but many scientists and engineers require such capabilities daily.
Extension modules for Python can be written in C or C++. Such modules allow easy extension of Python with functions and new types. The guidelines for writing such extension modules are available as part of the standard Python library reference and described at some length in Programming Python as well. One common use of extension modules is to write interfaces between Python and existing libraries, which can contain hundreds or thousands of single functions. When this is the case, the use of automated tools is a lifesaver. David Beazley's SWIG, the Simple Wrapper Interface Generator, is the most popular such tool. It's available at http://www.swig.org and is very well documented. With SWIG, you write simple interface definitions, which SWIG then uses to generate the C programs that conform to the Python/C extension guidelines. One very nice feature of SWIG is that when it's used to wrap C++ class libraries, it automatically creates so-called shadow classes in Python that let the user manipulate C++ classes as if they were Python classes. SWIG can also create extensions for other languages, including Perl and Tcl.
Anyone doing serious GUI work with Tkinter should check out Pmw, a 100% Python framework built on top of Tkinter, designed to allow the creation of megawidgets (compound widgets). Pmw, written by Greg McFarlane, is the next step beyond Tkinter, and learning it can pay off in the long run. Pmw's home page is at http://www.dscpl.com.au/pmw/.
If the notion of programs talking to programs is of interest to you, but you want a solution that works on platforms with no COM support, there are many other packages with similar functionality. Two favorites are ILU and Fnorb.
ILU stands for Xerox PARC's Inter Language Unification project. It's free, well-supported, stable, and efficient, and supports C, C++, Java, Common Lisp, Modula-3, and Perl 5, in addition to Python. It's available at ftp://ftp.parc.xerox.com/pub/ilu/ilu.html.
Unlike ILU, Fnorb is written in Python and supports only Python. It's especially helpful for learning more about CORBA systems, since it's easy to set up and play with once you know Python. Fnorb is available from http://www.dstc.edu.au/Fnorb/.
|I l@ve RuBoard|