def whichmodule(func, funcname):
 mod = getattr(func, '__module__', None)
 if (mod is not None):
  return mod
 if (func in classmap):
  return classmap[func]
 for (name, module) in sys.modules.items():
  if (module is None):
   continue
  if ((name != '__main__') and (getattr(module, funcname, None) is func)):
   break
 else:
  name = '__main__'
 classmap[func] = name
 return name

def whichmodule ( func , funcname ) : mod = getattr ( func , '__module__' , None ) if ( mod is not None ) : return mod if ( func in classmap ) : return classmap [ func ] for ( name , module ) in sys . modules . items ( ) : if ( module is None ) : continue if ( ( name != '__main__' ) and ( getattr ( module , funcname , None ) is func ) ) : break else : name = '__main__' classmap [ func ] = name return name
figure out the module in which a function occurs .