On Jun 7, 2012, at 6:12 PM, Cliff Kachinske wrote: > Does that mean there's only one instance of current for a running instance of > Web2py? So if I do current.db, it could overwrite a current.db assigned in > an earlier request?
No, it's unique to the current request (that's why it's called current). But web2py itself saves things there, like current.request, and there's no guarantee that it might not save something like current.db in the future, which you'd be clobbering. So you're better off doing something like current.app = Storage() current.myappname.db = db Nag: I really think that we should be executing that first line in gluon itself, and officially reserve current.app for use by the app. > > On Thursday, June 7, 2012 7:07:35 PM UTC-4, Jonathan Lundell wrote: > On Jun 7, 2012, at 2:42 PM, Cliff Kachinske wrote: >> I don't have a good feel for the most efficient way to, for example, pass >> the db to a class method. I can think of three ways. >> >> - Pass it in when you call the method. >> - Pass it in when you initialize the class >> - Import current, do something like current.db = db and then pass current to >> the class's __init__ >> >> Any opinions on this? All help greatly appreciated. > > It shouldn't really matter. But where is the caller and callee? If the caller > is in a controller and the callee is in an imported module, for example, I > don't think it makes much difference. I'd avoid current where you don't > really need it (and if you do use current, using current.db is a little > risky; try to give yourself a safe namespace).

