Alternatively if this is just a script (like cron) or a simple program and you do not mind loading the entire web2py environment
python web2py.py -S welcome -M -R /path/to/my/script.py -S denotes the app name, -M denotes execute models and -R is the path to the script to execute in the environment, if you do not specify -R then you get a python shell in the current environment. Remember, you will always need to explicitly call db.commit() from scripts. -Thadeus On Mon, Mar 29, 2010 at 9:00 AM, rfx_labs <[email protected]> wrote: > Hi Giovanni, > > I had the same problem and here is my simple solution: > > model.py: > from gluon.dal import DAL, Field > > db = DAL("sqlite://storage.db") > > db.define_table("reference", > Field("name", "string", notnull=True), > Field("L", "double"), > Field("a", "double"), > Field("b", "double")) > > myApp.py: > from model import db > > rows = db().select(db.reference.ALL) > > for row in rows: > print row.name, row.L, row.a, row.b, "\n" > > If you want to use a model file from a existing web2py application > without adding the import statement (from gluon.dal import DAL, > Field). You could import the model like this: > > model.py: > db = DAL("sqlite://storage.db") > > db.define_table("reference", > Field("name", "string", notnull=True), > Field("L", "double"), > Field("a", "double"), > Field("b", "double")) > > myApp.py: > from gluon.dal import DAL, Field > > model = open("/Users/mhufsky/Desktop/model.py", "rb") > exec model > model.close() > > rows = db().select(db.reference.ALL) > > for row in rows: > print row.name, row.L, row.a, row.b, "\n" > > In my app I prefer the import method. > > Hint: To get same output you should first insert something to the db. > Hint2: The db is stored in the working directory. You could specify a > other folder relative to the working dir or absolute (starting > with /): > db = DAL("sqlite://storage.db", folder="/path/to/Folder") > > > Martin > > -- > You received this message because you are subscribed to the Google Groups > "web2py-users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/web2py?hl=en. > > -- You received this message because you are subscribed to the Google Groups "web2py-users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/web2py?hl=en.

