You need to look for the name as a string; and I'd use hasattr()
here to test for that name:
if hasattr(my_module, 'exists_method'):
print 'Method found!"
This works if my_module.exists_method
exists, but not if you run this code inside my_module
.
If exists_method
is contained in the current module, you would need to use globals()
to test for it:
if 'exists_method' in globals():
print 'Method found!'