Tim

Thanks for your response. I'm still a Python newbie, especially with
some of the more esoteric stuff.

With the plugin demo I have code in sql.py outside any class that
appears to only run the once (when sql.py is imported I assume) and,
as you suggest, it loads details of the available db-plugins.  I will
try wrapping the code in a function outside a class and see if it runs
in the same way - on import - or does it need to be named anything in
particular?

BTW in the case of the db-plugins all the data and functions are
static or class - you don't have to create an instance of a plugin.  I
don't know yet whether that is an advantage/disadvantage or
immaterial.

On the more general point, in the original question I was thinking
about how I would want to configure an application with regard to
dynamically loading modules, plugins, configuration options, etc.  If,
for example, I had a "Configurator" class, where would I import it?

If I understand things correctly:

- it couldn't be in a controller file as there may be an interaction
with the model in db.py and it may not have been imported by the time
db.py is run (is that correct?)

- it could be in db.py but that seems conceptually wrong as it may
have no db element at all

- any other ideas?

Coming from Java, it takes a bit of effort to get to grips with the
elasticity of Python :-)

On Jan 27, 2:14 pm, Timothy Farrell <tfarr...@swgen.com> wrote:
> I'm not sure what you're getting at here, but if you consider Python is
> a very dynamic language.  Whenever a module is imported, it is
> essentially run in it's own namespace.  In the case of your plugin
> (driver) system (which I haven't looked at yet), you could have an
> SQLDBFactory function that runs at import-time, loading the available
> db-engine plugins, and producing a functional SQLDB class.
>
> Reimporting a module does not re-run the module unless you call
> reload(modname).  If you have code that you want to run once, put it in
> a module that is normally imported (such as sql.db)
>
> This is the area where Javascript has made me a better Python
> programmer.  =)
>
> -tim
>
> billf wrote:
> > Basically, is there any code that receives control when an application
> > first starts that allows some initialisation/configuration that
> > doesn't have to run after every request?
>
> > I believe code could be put in db.py but that is not ideal
> > conceptually - and would run on every request?
>
> > I can see that there are pros and cons to the idea of "on start" code
> > and would be interested in peoples' views.
>
> --
> Timothy Farrell <tfarr...@swgen.com>
> Computer Guy
> Statewide General Insurance Agency (www.swgen.com)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to