[Zope-dev] Re: Execution context

Tres Seaver tseaver at zope.com
Tue Mar 2 21:33:28 EST 2004


Garito wrote:
> Can I know the execution contexto of an object?
> 
> I would like to know if the object is call by ZMI or DTML or Page Templates etc
> 
> is it posible?

Perhaps;  I am not sure I can see why it would be *desirable*.  Given 
that Scripts, DTMLMethods, etc., try pretty hard to push themselves onto 
the execution stack just as though they were methods, you could probably 
introspect the result of calling 'sys._getframe(1)' to figure out what 
kind of thing called you.

 From the Python Cookbook, #14.7:

    >>> def whoami():
    ...     """ Return the name of the calling function.
    ...     """
    ...     import sys
    ...     return sys._getframe(1).f_code.co_name
    ...
    >>> def foobar():
    ...     print whoami()
    ...
    >>> foobar()
    foobar


Tres.
-- 
===============================================================
Tres Seaver                                tseaver at zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com




More information about the Zope-Dev mailing list