Testing if a global is defined in a module

Ian Kelly ian.g.kelly at gmail.com
Tue Jul 5 06:28:42 CEST 2011


On Mon, Jul 4, 2011 at 6:01 PM, Tim Johnson <tim at johnsons-web.com> wrote:
>> Yes, but what are you actually *trying to do*? "Detecting data members" is
>> not an end in itself. Why do you think you need to detect data members?
>
>  Steven, I'm building a documentation system. I have my own MVC framework
>  and the goal is to have a documentation module for each project.

It sounds like what you really want is to detect the names *exported*
by the module, then.  Why not do it the same way Python does it?  If
the module defines an "__all__" attribute, then it is taken to be a
sequence of strings which are the exported names.  Otherwise, the
exported names are taken to be all the names in the module dict that
don't begin with an underscore.

Cheers,
Ian



More information about the Python-list mailing list