[IronPython] Python Module Scopes versus WinForms Event Handlers

Kevin Bjorke KBjorke at nvidia.com
Thu Jun 29 16:52:15 PDT 2006


A typical idiom for a global value is to define it in some imported
module, e.g.

    # config.py
    gVal = 3


And then all the other modules can

    import config

And get/set the value by accessing "config.gVal"

Unfortunately, this gets broken when using WinForms! It seems that in
methods called as event handlers (or any methods called by those
methods) that (in this case) "config.gVal" is not a valid attribute. For
all other method contexts, "config.gVal" works perfectly.

A global declared within the scope of the module containg the event
handler CAN be used within the event handler, so my modules end up doing
something like this:



    import config
    global gVal
    # ...and somewhere before any other code in the current mdule gets
executed....
    gVal = config.gVal

...so that event handlers can use the local-module "global" version.

Obviously if the value of "config.gVal" changes a lot this would be an
even huger hassle (fortunately, all I want is to maintain a
globally-available pointer to my top-level app, which never changes once
the app is initialized)
-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------


More information about the users mailing list