Forgot to reply to this earlier but I ended up putting them in a module to be imported.
Incidentally, I noticed when importing a module (from outside the regular system path for python libs) into a model, I needed to append the app/modules folder path before doing the import. Never needed to import anything from modules into a model before (just controllers) but wanted to mention it in case someone else does this. Thanks again. On Thursday, February 1, 2018 at 4:08:02 PM UTC-7, Anthony wrote: > > 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

