How can I know which members module/package defines? By defining I mean:
somemodule.py
import os # <-- Not defined in this module
from os.path import sep # <-- Not defined in this module
I_AM_ATTRIBUTE = None # <-- Is defined in this module
class SomeClass(object): # <-- Is defined also...
pass
So I need a some sort of function that when called would yield only I_AM_ATTRIBUTE and SomeClass.
Now I have been trying to do using dir(somemodule), but how can I know which ones are defined in somemodule? Checking against __module__ does not work, since that is not defined in modules and attributes (such as os package, or sep attribute).
Apparently wild import (from somemodule import *) also fails to filter those, so is it even possible?
Best I can get is:
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
Takes os out, but leaves sep.