How to globalize vars ???

fowlertrainer at anonym.hu fowlertrainer at anonym.hu
Fri Jan 9 16:29:39 CET 2004


Hello !

I have get a strange problem in mod_python site.
More modules I have, and think, to I initialize my Session handler
from main module.

Like this:

-- main --

import BHASession

# Session info
BHASessionDir="C:/bhaweb/sessions"
BHASession.SSInit(BHASessionDir)

-- Session --
SSDefaultDir="c:/bhaweb/sessions"
SSLockObj=threading.Lock()

def SSLock():
    SSLockObj.acquire()

def SSUnlock():
    SSLockObj.release()

def SSInit(SessionDir):
    SSLock()
    try:
      if SSDefaultDir.strip()=="":
#       <-
# UnboundLocalError: local variable 'SSDefaultDir' referenced before assignment
         SSDefaultDir=SessionDir
    finally:
      SSUnlock()

--------------
      
When I not use SSInit, only I write the global variable in BHASession
module like this:

SSDefaultDir="c:/bhaweb/sessions"

then it is working good !!!

Why ? How to force python to module see his variable ?

Thanx for any advance  !

-- 
Best regards,
 fowlertrainer                          mailto:fowlertrainer at anonym.hu





More information about the Python-list mailing list