On 2006-01-31, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
>
> def ExpensiveObject():
> global _expensiveObject
> if _expensiveObject is None:
> _expensiveObject = "A VERY Expensive object"
> print "CREATED VERY EXPENSIVE OBJECT"
> return _expensiveO
Charles Krug wrote:
> > 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
> Okay, that
On 2006-01-31, Farshid Lashkari <[EMAIL PROTECTED]> wrote:
> 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 functio
Charles Krug wrote:
> List:
>
...
> # expensive Object Module
>
> _expensiveObject = None
> def ExpensiveObject():
>
> if not(_expensiveObject):
> _expensiveObject = "A VERY Expensive object"
>
> return _expensiveObject
>
...
> I obviously missed some part of the scoping rules.
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():