I want to get the list of all the variables defined in a Python module, without the imported variables. With classes or functions, it can be done with
inspect.getmembers , for example:
getmembers(module, lambda member: isclass(module) and member.__module__ == module.__name__)
However, simple objects don’t seem to have the
__module__ field, so I can’t check if they have been imported or have been defined in the module directly.
If I restrict the user from using
from ... import statements, and only use
__init__.py files which don’t import simple variables it can work, since it is not possible to import them, but it is not a satisfying solution…
Is there a way to list variables defined in a Python module, excluding imported ones ?