Getting Instance of calling class
antonmuhin.REMOVE.ME.FOR.REAL.MAIL at rambler.ru
Tue Jun 17 12:04:04 CEST 2003
Thomas Güttler wrote:
> I have a function called _() which prints
> strings according to the language of the user.
> I don't want to give this method the object which
> holds the language information every time I call it.
> How can I access the calling object?
> Background: This is a python product for zope.
> My main object holds the prefered language of each
> I found no way to get a reference to my main
> object from _(). Global variables are no solution
> since there could be several main objects and there
> are multiple threads.
You can find a caller with get_frame trickery (google for it---this
issue has been discussed already). However, I think you should stick to
another solution. As a simple example:
# Language dependent code goes here
user = current_user()
report_function = user.print_msg
More information about the Python-list