You definitely want to use python-wnck(for documentation, you may need to search python-gnome-extrasor bind Perl or just plain C documentation). WNCK is written to make viewing screens, workspaces and windows easier. Something like that:
import pygtk
pygtk.require('2.0')
import gtk
import wnck
screen = wnck.screen_get_default()
while gtk.events_pending():
gtk.main_iteration()
windows = screen.get_windows()
for w in windows:
if w.get_name() == 'foo':
w.close(0)
... but I have not tested it.
( , GNOME, .)