Questions about the event loop

bruno at modulix onurb at xiludom.gro
Tue May 16 16:52:23 CEST 2006

egbert wrote:
> What does a gui_event_loop know ?
> My gui is based on pygtk, 
> but i suppose the mechanism is the same everywhere.
> The gui is created within a class-instance within a function.
> Normally, ie without a gui, everything that happens within
> a function is forgotten as soon the function ends.
> But in a gui_event_loop the callback-method within the function
> can be called, and this callbacks calls another function
> also within the same first function.
> And that function already stopped.


I guess that what bother you has to do with closures.

def foo(bar):
  buu = "buu"
  def baaz(baak):
    print  bar, buu, baak

  print "foo(%s") return..." % bar
  return baaz

dodo = Foo('parrot')
dudu = Foo('dead')


As you can see, after foo() has returned, dodo() and dudu() 'remember'
the environment in which they where created. A closure is a function
that carries it's environment with it.

> Maybe somebody can explain what is going on, or where I can find
> further explanations.

bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"

More information about the Python-list mailing list