Marino is referring to the method I mentioned earlier of using modules and 
the singleton pattern. You could use this in combination with Michele's 
mmap suggestion to hold the data to do what you want.

I've never used mmap before, but I can get you on the right track with 
modules. This is a very (very) simple example, but it works:

Create a module called "mymodule.py" and put the following line in it:

count = 0

Then in your controller, put the following code in:

import mymodule
    
count = mymodule.count
mymodule.count += 1
    
return dict(count=count)

Then in your view, put this somewhere:

{{=count}}

Every time you visit that page, the number will increment. The purpose of 
this is to show you that module (not models) stick around once you import 
them. The only way to update the module (like if you changed some code in 
it) is to restart web2py. So once you import this module, it will continue 
to increment the number. The only way to make it "forget" the number is to 
restart web2py.

Reply via email to