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.