A startup puzzle

Edward K. Ream edreamleo at charter.net
Mon Sep 29 17:27:39 EDT 2003


> Perhaps using a proxy object...might work:

Great idea!  Some complications:

1. Sometimes the test "if not realApp:" causes unbounded recursion.  To
avoid any possibility of this happening the startup code just creates the
app object before any code actually uses the app proxies.  This is easily
done.

2. A __call__ method in the proxy allows the code to use either app().x or
app.x.

In short, the following pattern appears like it will work in all my modules:

from leoGlobals import *
app = leoProxy() # leoProxy defined in leoGlobals
# Now the code can reference either app.x or app().x.

To do this, I use the following code:

gApp = None # Set before any reference to proxy.
class leoProxy:
  def __getattr__(self,attr):
    return getattr(gApp,attr)
  def __call__(self):
    return gApp

Many thanks for this great idea.

Edward
--------------------------------------------------------------------
Edward K. Ream   email:  edreamleo at charter.net
Leo: Literate Editor with Outlines
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------









More information about the Python-list mailing list