Artificial Intelligence in Python

Python has many of the features of LISP, a language very popular among artificial intelligence (AI) researchers. It is well suited to the sort of symbolic processing used in AI.

I'm no expert in AI, but I've tinkered a bit. As I develop more AI programs in Python, I'll post them here. If you have something or know of something along these lines, please let me know and I'll include it here as well.

Therapist is a little Python program inspired by ELIZA, a famous natural-language AI demo from the 1960s. It's all smoke and mirrors; the program hasn't the foggiest idea what it is saying, and you'll find that tripping it up is fairly easy. But it's at least amusing, and may occasionally be theraputic.

Python2C is close relative of therapist -- a little smaller, more serious, and just as cheezy. This program attempts to convert Python code into the equivalent C++ code, as in this example. It's very limited in this skill, but it does demonstrate the concept of a Python compiler. This program was updated by Dirk Heise in January 1998, and now does significantly more transformation -- it could now be considered actually useful in some cases!

For another attempt at a Python to C converter, see: Issues in Building Ariel -- OpenGL and Python to C.

Semantic Networks


The following classes are defined:

With these three object types, you can very quickly define knowledge about a set of objects, and query them for logical conclusions. For example, if you declare that a fish is an animal, and animals are made of cells, it will automatically know that fish are made of cells. If you further assert that cells are made of molecules, it will know that fish are made of molecules.

In addition to (which does nothing interesting on its own), I've prepared two demo programs. shows how to build and query a semantic net directly from Python code; have a look to see how easy it is! shows how to do the same thing, but with an interactive user interface (you'll also need for this).

Expert-System Inference Shell

Mark Lutz has developed an expert-system shell. It is available on the Python archives:
Thanks, Mark!
Last Updated: 1/16/98 . . . . . . Joe Strout