How to check version of Python under CGI

Duncan Booth duncan at
Thu Jun 13 05:31:22 EDT 2002

Johann <observer at> wrote in 
news:cgnggu40ethjhpqcmltnfb06d5qvuf078k at

> Thanx. Do you know how to check what modules are installed? E.g. I
> would like to check if PYANA or other xml modules are installed.

Try importing them and handle the exceptions that are thrown if they don't 
exist. Either wrap the import directly in a try:except: block, or define a 
function using __import__:

>>> def modAvailable(name):
	except ImportError:
		return 0
	return 1

>>> print modAvailable('sys')
>>> print modAvailable('junk')

Duncan Booth                                             duncan at
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?

More information about the Python-list mailing list