On Wednesday, November 30, 2011 6:56:50 PM UTC-5, lyn2py wrote: > > Good thing you mentioned Bruno's solution. It appeared as "show quoted > text" to me, and at first glance didn't look like it contained new > text. *sorry Bruno!* > > Just a side question on best practices, where should I put my little > lambda so that all files (and functions) in my app can use it? Geez, > did I mention I'm new to python too... > The simplest thing to do is put it in a model file (maybe called 0_helpers.py, or if it's a simple app and you just have one or two, stick it in db.py). (Note, model files are executed in alphabetical order, so preceding the file name with "0_" ensures it will be executed early and the helpers will therefore be available in later executed model files.) You could also put it in a module and import it where needed, but in that case, the module will have to import the IS_SLUG validator from gluon.validators. There are a number of API objects (including validators) that are automatically imported into the web2py execution environment and are therefore available in any model, controller, or view without requiring explicit import (http://web2py.com/book/default/chapter/04#API). However, those API objects are not readily available in modules, so they must be imported there (see http://web2py.com/book/default/chapter/04#Accessing-the-API-from-Python-modules).
Anthony

