Controller and model files are not Python modules. Rather, they are 
re-executed (in a separate thread) on each request, so a change you make to 
a global variable in one request will not affect other requests. You 
probably want to use the cache for this purpose: 
http://web2py.com/books/default/chapter/29/4#cache.

Anthony

On Monday, May 21, 2012 12:09:14 PM UTC-4, Madu wrote:
>
> Hi,
>
> I thought this could be trivial but so far I couldn't figure out how to.
> All I need to do is have a global variable in default.py. When I call one 
> method it will store a value in this variable, and later another method 
> will use it. What I have is something like this:
>
>
> ------- default.py-----
> value = 0
>
>
> def saveValue():
>         global value
>         value = 1
>
>         
> def showValuel():
>         return dict(entries=value)
>
> Then I thought the default.py module maybe going out of scope when the 
> method returns, so I put 'value' in db.py, since variables defined in db.py 
> are available globally. But I still get the value that I define in db.py, 
> not the modified value in saveValue().
>
> Could you please tell me if there is a recommended way in web2py to 
> have global values?
>
> Thank you.
>

Reply via email to