How to check version of Python under CGI

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Jun 13 05:31:22 EDT 2002


Johann <observer at NOSPAM.space.pl> wrote in 
news:cgnggu40ethjhpqcmltnfb06d5qvuf078k at 4ax.com:

> 
> 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):
	try:
		__import__(name)
	except ImportError:
		return 0
	return 1

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

-- 
Duncan Booth                                             duncan at rcp.co.uk
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