[Zope] how to create a module global variable ?

Jerome Alet alet@librelogiciel.com
Thu, 3 Apr 2003 11:14:28 +0200


On Thu, Apr 03, 2003 at 10:49:32AM +0200, Stefan H. Holek wrote:
> You have to use global because you are assigning to _MySharedVar. The 
> _markers are never assigned to so they do not need global.

I beg to disagree. The "if" is causing the exception, not the following
line on which the assignment takes place. At least that's the line
number which is reported (could it be false ?).

With the global keyword it works but I still don't understand why...

Thanks anyway.

> >
> >    def myMethod(self) :
> >        """My method."""
> >        if _MySharedVar is None :
> >            _MySharedVar = "yes"
> >
> >the "if" raises and UnboundLocalError, saying that I use
> >_MySharedVar before assignment.

Jerome Alet