title: All members package/module defines?
body: <p>How can I know which members module/package defines? By defining I mean:</p>
  
  <p><strong>somemodule.py</strong></p>
  
  <pre><code>import os # &lt;-- Not defined in this module
  from os.path import sep # &lt;-- Not defined in this module
  
  I_AM_ATTRIBUTE = None # &lt;-- Is defined in this module
  
  class SomeClass(object): # &lt;-- Is defined also...
      pass
  </code></pre>
  
  <p>So I need a some sort of function that when called would yield only <code>I_AM_ATTRIBUTE</code> and <code>SomeClass</code>.</p>
  
  <p>Now I have been trying to do using <code>dir(somemodule)</code>, but how can I know which ones are defined in <code>somemodule</code>? Checking against <code>__module__</code> does not work, since that is not defined in modules and attributes (such as <code>os</code> package, or <code>sep</code> attribute).</p>
  
  <p>Apparently wild import (<code>from somemodule import *</code>) also fails to filter those, so is it even possible?</p>
  
  <p>Best I can get is:</p>
  
  <pre><code>import somemodule
  
  for name in dir(somemodule):
      try:
          value = getattr(somemodule, name)
      except:
          pass
      else:
          if hasattr(value, "__module__"):
              if value.__module__ != somemodule.__name__:
                  continue
          if hasattr(value, "__name__"):
              if not value.__name__.startswith(__name__):
                  continue
          print "somemodule defines:", name
  </code></pre>
  
  <p>Takes <code>os</code> out, but leaves <code>sep</code>.</p>