A Python module is an object. hasattr()
works just fine on that.
Demo:
>>> import os
>>> type(os)
<type 'module'>
>>> os
<module 'os' from '/Users/mj/Development/venvs/stackoverflow-2.7/lib/python2.7/os.pyc'>
>>> hasattr(os, 'sep')
True
>>> hasattr(os, 'foobar')
False
If you have a string with the module name, then you can look up the module object in the sys.modules
mapping:
>>> import sys
>>> sys.modules['os']
<module 'os' from '/Users/mj/Development/venvs/stackoverflow-2.7/lib/python2.7/os.pyc'>
>>> hasattr(sys.modules['os'], 'sep')
True