stupid Python/database connection

Terry Reedy tjreedy at udel.edu
Mon Nov 25 14:51:25 EST 2002


"animeshk" <animeshk at yahoo.com> wrote in message
news:4cce07d5.0211250918.5c97a929 at posting.google.com...
> So . . . how can the decision of what-database-to-use be defferred
to
> runtime?  When writing, say, a BDE app in Delphi, it would be a
simple
> matter of what alias to use.  How is this done in Python?

For the runtime selection of what module to import: if the name of the
database module you actually want is in a program variable as a
string, you can write

db = __import__(database_module)

If database_module == 'somedbmodule', then this works just like

import somedbmodule as db

Terry J. Reedy





More information about the Python-list mailing list