[Zope] how to create a module global variable ?

Andreas Jung Andreas Jung <andreas@andreas-jung.com>
Thu, 03 Apr 2003 11:19:34 +0200


see <http://www.faqts.com/knowledge_base/view.phtml/aid/4722/fid/241>
but stop the discussion at this point...this is python country.

-aj

--On Donnerstag, 3. April 2003 11:14 Uhr +0200 Jerome Alet 
<alet@librelogiciel.com> wrote:

> 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
>
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists -
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )