function access to caller's symbols?

Alex Martelli aleaxit at yahoo.com
Fri Mar 9 18:12:04 EST 2001


"Lance E Sloan" <lsloan at yahoo.com> wrote in message
news:mailman.984165207.5080.python-list at python.org...
> I'm a Python newbie, so if I'm approaching this problem
> the wrong way, let me know.
    [snip]
> So, how can I make my function access its caller's
> symbol table?

This is indeed an unnecessarily complicated approach in
most cases (though you can access the caller's global
symbols by raising and catching an exception, and using
the resulting traceback object to walk the stack).  I would
strongly suggest NOT using such black-magic tricks, by
making the directory arg not optional -- the caller may
very well pass globals() explicitly if it wants.


Alex






More information about the Python-list mailing list