Import a module without executing it?

Jay O'Connor joconnor at cybermesa.com
Tue Dec 7 15:19:19 EST 2004


Is there a good way to import python files without executing their content?

I'm trying some relfection based stuff and I want to be able to import a 
module dynamically to check it's contents (class ad functions defined) 
but without having any of the content executed.

For example:
----------------------
def test(var):
	print var


#main
test(3)
----------------------

I want to be able to import this module so I can see "ah ha, this module 
defines a function called 'test'", but I don't want  the code at the 
bottom executed during the import.

Thanks

Take care,
Jay



More information about the Python-list mailing list