Yes, in this regard web2py is not quite like most other Python web 
frameworks. All of your model files are executed in a prepared environment 
that includes various framework objects, such as request, response, session, 
and many of the API objects. Your controller is then executed in that 
environment after the models have been run, so whatever objects have been 
created in your models are available in the controller. If your controller 
function returns a dictionary, the execution environment is then updated to 
include the items in the dictionary, and your view is executed in that 
updated environment.

So, the "boundaries of this happy sharing," as you put it, are the model, 
controller, and view files (note, the view files see everything created in 
the model files, but only the items returned in the dictionary of the 
controller function, not any other objects created in the controller).

Any other code you want to access (e.g., Python standard library, Python 
site-packages, files in your application's 'modules' folder) have to be 
imported as usual.

See http://web2py.com/book/default/chapter/04#Dispatching (particularly the 
bulleted list near the end of the section) and 
http://web2py.com/book/default/chapter/04#Execution-Environment (first 
paragraph).

Anthony

On Thursday, September 8, 2011 8:13:05 PM UTC-4, Luca wrote:
>
> I understand, but this is very un-python like and weird... you mean that if 
> I have 
>
> a = 1
>
> in a file, and then load another file, then a is still 1 also in the other 
> file?  This is incredibly weird to me -- normally, files have to import each 
> other to share variables in this way. 
>
> Ok... now I just wonder what the precise boundaries of this happy sharing 
> are.  Thanks!!
>
> Luca
>

Reply via email to