How to globalize vars ???

F

fowlertrainer

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 !
 
M

Miki Tebeka

Hello,

Warning: Fix not tested.
def SSInit(SessionDir):
global SSDefaultDir # FIX
SSLock()
try:
if SSDefaultDir.strip()=="":
# <-
# UnboundLocalError: local variable 'SSDefaultDir' referenced before assignment
SSDefaultDir=SessionDir
finally:
SSUnlock()
Why ? How to force python to module see his variable ?
By definition all new variables are local to their function.

HTH.
Miki
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top