In <[EMAIL PROTECTED]>, robert wrote:

> Marc 'BlackJack' Rintsch wrote:
>> In <[EMAIL PROTECTED]>, robert wrote:
>> 
>>>The fact is:
>>>* Python has that big problem with unnecessary barriers for nested frame 
>>>access - especially painfull with callback functions where you want to 
>>>put back data into the calling frame.
>> 
>> 
>> You mean accessing the locals in the function that invoked the callback!? 
>> That sounds ugly.  Makes it hard to decouple the caller and the callee
>> here.
>> 
> 
> That is a frequent need. For read's its anyway wired up. E.g. callbacks:
> 
> def f():
>      a=1
>      def g(var):
>          print a             # automatic
>          .lastvar=var        # binds in outer frame
>      run_w_callback(1,2,g)
>      print lastvar
> 
> 
> Ruby blocks for example do that regularly.

I think you're trying to write Ruby programs in Python here.  Just define
a callable object as callback::

 class G:
     def __init__(self, a):
         self.a = a
         self.lastvar = None
    
     def __call__(self, var):
         print self.a
         self.lastvar = var

 def f2():
     g = G(1)
     run_w_callback(1, 2, g)
     print g.lastvar

Ciao,
        Marc 'BlackJack' Rintsch
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to