How to globalize vars ???

Discussion in 'Python' started by fowlertrainer@anonym.hu, Jan 9, 2004.

  1. Guest

    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:
    , Jan 9, 2004
    #1
    1. Advertising

  2. Miki Tebeka Guest

    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
    Miki Tebeka, Jan 11, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon

    app vars and cache vars

    Jon, Dec 14, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    382
  2. Linuxguy123
    Replies:
    7
    Views:
    670
    Paddy O'Loughlin
    Feb 20, 2009
  3. Tom
    Replies:
    3
    Views:
    431
    Steven D'Aprano
    Jul 26, 2009
  4. HawX

    Globalize-rails plugin

    HawX, Jul 17, 2006, in forum: Ruby
    Replies:
    0
    Views:
    89
  5. OHaleck
    Replies:
    3
    Views:
    181
    Mohit Sindhwani
    Oct 8, 2007
Loading...

Share This Page