code: def getmodule(object):
      
      if ismodule(object):
          return object
      if isclass(object):
          return sys.modules.get(object.__module__)
      try:
          file = getabsfile(object)
      except TypeError:
          return None
      if modulesbyfile.has_key(file):
          return sys.modules[modulesbyfile[file]]
      for module in sys.modules.values():
          if hasattr(module, '__file__'):
              modulesbyfile[getabsfile(module)] = module.__name__
      if modulesbyfile.has_key(file):
          return sys.modules[modulesbyfile[file]]
      main = sys.modules['__main__']
      if hasattr(main, object.__name__):
          mainobject = getattr(main, object.__name__)
          if mainobject is object:
              return main
      builtin = sys.modules['__builtin__']
      if hasattr(builtin, object.__name__):
          builtinobject = getattr(builtin, object.__name__)
          if builtinobject is object:
              return builtin
docs: Return the module an object was defined in, or None if not found.