Almost. You cannot do do this: self.env = Storage(globals()) self.cache = self.env.cache self.request = self.env.request self.response = self.env.response self.db = self.env.db self.obj1 = self.env.obj1 self.obj2 = self.env.obj2
but you can do current.db = db current.obj1=obj1 current.obj2=obj2 ... (in model) and self.cache =current.cache self.request = current.request self.response = current.response self.db = current.db self.obj1 = current.obj1 self.obj2 = current.obj2 (in module) I would still pass db,obj1 and obj2 explicitly and try avoid circular references as possible (they increate time for garbage collection). On May 5, 8:10 am, Ross Peoples <ross.peop...@gmail.com> wrote: > I work a lot with modules, so I have a question. I have a > 'z_import_modules.py' model that would look something like this: > > DEBUG = True > module1 = local_import('module1', reload=DEBUG) > module2 = local_import('module2', reload=DEBUG) > module3 = local_import('module3', reload=DEBUG) > > obj1 = module1.Object1(globals(), db) > obj2 = module2.Object2(globals(), db) > obj3 = module3.Object3(globals(), db, obj1, obj2) > # obj3 is dependent on obj1 and obj2 instances > > And my Object3 class' init method might look like this: > def __init__(self, environment, db, obj1, obj2): > self.env = Storage(environment) > self.cache = self.env.cache > self.request = self.env.request > self.response = self.env.response > self.db = db > self.obj1 = obj1 > self.obj2 = obj2 > > With the new changes in the trunk, would I be able to rewrite my > 'z_import_modules.py' model to this? > > from module1 import Object1 > from module2 import Object2 > from module3 import Object3 > > obj1 = Object1() > obj1 = Object1() > > And would I be able to rewrite Object3's init method to something like this: > def __init__(self): > # assuming from gluon import * > self.env = Storage(globals()) > self.cache = self.env.cache > self.request = self.env.request > self.response = self.env.response > self.db = self.env.db > self.obj1 = self.env.obj1 > self.obj2 = self.env.obj2 > > Is this what you mean by "only need to do "from gluon import *" to see > everything web2py has to offer"?