Re: Having Trouble with Scoping Rules
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.python archive

Re: Having Trouble with Scoping Rules

From: Farshid Lashkari <flashkNO@SPAMgmail.com>
Date: Tue Jan 31 2006 - 04:09:35 CET

You need to declare _expensiveObject as global inside your function.
Whenever you assign something to a variable that resides in the global
scope inside a function, you need to declare it as global at the
beginning of the function. So your function should look like this

def ExpensiveObject():
     global _expensiveObject
     if not(_expensiveObject):
         _expensiveObject = "A VERY Expensive object"

     return _expensiveObject

The documentation will no doubtedly explain it better than I have

-Farshid
Received on Tue Feb 7 20:18:39 2006