On Thursday, February 1, 2018 at 4:53:59 PM UTC-5, Jordan Ladora wrote:
>
> Hi Anthony,
>
> Thanks again for this. I had dozens of vars that were needlessly declared 
> as session vars. 
>
> I was wondering how to make global vars declared in a model accessible 
> from a compiled module (that is placed in the modules folder and imported 
> when needed by models and controllers)? e.g. from your example above, how 
> could a compiled module access the DECPLACES global variable?
>

There are  a couple options. First, you could put those constants 
themselves in a module instead of a model file, and then import them into 
models, modules, controllers, etc. Alternatively, in your module, you can 
do something like:

from gluon import current

def some_function():
    decplaces = current.globalenv['DECPLACES'] # This goes inside a 
function, not at the top level of the module.
    ...

current.globalenv is a dictionary of the web2py global environment.

I would probably take the first approach.

Anthony

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to