Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > How to globalize vars ???

Reply
Thread Tools

How to globalize vars ???

 
 
fowlertrainer@anonym.hu
Guest
Posts: n/a
 
      01-09-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 private.php?do=newpm&u=


 
Reply With Quote
 
 
 
 
Miki Tebeka
Guest
Posts: n/a
 
      01-11-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Globalize Management careers. gaurav Python 0 06-18-2011 01:57 PM
Globalize all variables in function without knowing names. Tom Python 3 07-26-2009 10:49 PM
Exec format error when installing Globalize Rails OHaleck Ruby 3 10-08-2007 06:59 AM
Globalize-rails plugin HawX Ruby 0 07-17-2006 07:40 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57