[IronPython] Python Module Scopes versus WinForms Event Handlers

Kevin Bjorke KBjorke at nvidia.com
Sun Jul 2 17:39:32 CEST 2006

This ended up being weirder and more subtle than I realized... And
possibly not an IP bug

I discovered that within the problematic scope, one module was using a
variable with the same name as an imported module -- and within that
narrow scope at least, was over-writing the namespace for the module.
This may have been at the root of the problems I was experiencing -- 

   import blah
   blah = 7

Is likely to cause an error since the "blah" namespace is actually an
object, no? In my case it was subtle since the re-assignment would only
happen when a certain combination of events occurred in a running
program, only after the entire thing was up and running with all windows
initialized and so forth, and only within certain parts of the program.

I'm now re-revising my code to use "normal" global scopes again, and if
it's all good, won't write about this issue any more ^_^;; 

(*sometimes* missing rigid typing, heh)

-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of Kevin Bjorke
Sent: Thursday, June 29, 2006 4:52 PM
To: Discussion of IronPython
Subject: [IronPython] Python Module Scopes versus WinForms Event

This message appears to be from an NVIDIA.COM e-mail address, yet did
not originate from an NVIDIA server.
Please be cautious of any attachments or links in this message.
Thank you, NVIDIA IT Team.
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
    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
is prohibited.  If you are not the intended recipient, please contact
the sender by
reply email and destroy all copies of the original message.
users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list