[Tutor] Accessing calling module's globals in a module

Jesse W jessw@loop.com
Fri, 22 Jun 2001 17:03:35 -0700


Christopher Smith wrote:

> I would like to be able to print a list of variable names and id's in
> a function.

I am probably misunderstanding what you are trying to do, but would 
this work?
def show_ids(func):
    """Return a list of name and id tuples from a given function."""
    ans=[]
    for ref in dir(func):
        ans.append((ref, eval('id('+func.func_name+'.'+ref+')')))
    return ans
If it _is_ what you need, I will explain how it works in a future 
message.

		Wow-what-a-nice-list-l'y,
					Jesse W