Looking up caller's namespace

Yves-Eric Martin yemartin at garage.co.jp
Fri May 26 05:43:04 EDT 2000


On 25 May 2000 12:40:15 GMT
scarblac-spamtrap at pino.selwerd.nl (Remco Gerlich) wrote:

> Yes, this is possible. But not in a nice way.
> 
> You raise some exception (like 1/0), and catch it. Name you look at the
> current exception as returned by sys.exc_info, and take the traceback
> object. Go up its stack using some of its methods and maybe functions in the
> traceback module, and find the function that called you, and its module.
> 
> However, this is black magic, implementation detail, meant for use in
> debuggers only, and probably not the sort of thing you would want in Zope.

    Yeah, I once thought there could be a solution using a traceback,
but as you say, that's evil. We definitively don't want to do that. I
was looking for a nice way, but it looks like there isn't any. I guess
I'll do with the workaround.


> I would try to set a default argument. I suppose you do
> 
> from somemodule import _
> 
> somewhere. Instead, I would try something like
> 
> import somemodule
> _ = somemodule.gettext_factory(sys.modules['__name__'])
> 
> Where the gettext_factory is a function that returns a _ function with the
> right default argument. I don't know if this is usable for you though.

    I don't think this will help with the present problem (the
information we would need to build the right function is not present
when this call is made), but I will probably do something like that to
simplify the "gettextification" process. Thanks for the idea.


    Thank you all for your help.

-- 
Yves-Eric Martin
Digital Garage Inc.
yemartin at garage.co.jp




More information about the Python-list mailing list