I'm sure this is a very fundamental Win2py or Python thing. I'm such a Noob.
I am writing a database populator program that I would like to run outside the framework to fill the database with test data. I have been struggling with importing the models from the application. Here's what I've tried: I put my standalone app in "web2py\alone" subdirectory to point to web2py directory, I use: ------------------------------------------------------- more_path = ".."+os.sep if more_path in sys.path: pass else: sys.path.append(more_path) ---------------------------------------------- then I find the model directory model_path = os.path.abspath("..\\applications\\myapp\\models") and add it to sys.path in a similar way ------------------------------------------------------ I try to import the database connection with: ------------------------------------------------------ import db --------------------------------------------------------- which complains there is no 'request'variable so I decided to open it directly with ----------------------------------------------- from gluon.dal import DAL, Field db = DAL('sqlite://storage.sqlite') ------------------------------------------------- Then when I try to import the data table statements with -------------------------- import pdpb # define the data tables -------------------------- which complains there is no 'db' I guess I need a form of import which is more like #include statements in C or assembly programming. Is this a scoping and/or namespace issue? How does the web2py framework seem to load the different .py files of a model prior to running the controller code yet have request, session, response variables available prior to executing the model code? while waiting for replies, I'll just have to put the database initter into a controller function inside the framework. (I really don't want to have multiple copies of duplicate table definition code.) In summary, I'd like to create a python program outside the web2py framework, using the same model files as used by the framework, so the program looks somewhat like: -------------------------------- ### some kind of path setups import db # get database connection import pbdb # get table definitions db.employee.insert(last_name="Smith", first_name="Rufus") db.commit() -------------------------------------- Thanks