Newbie Q: Import code at run-time?

James Knowles jamesk at
Mon Feb 25 01:43:07 EST 2002

To learn Python, I dove in and wrote a program that takes a series of
dictionaries that define a complete database structure and spits out the SQL
necessary to build that database in either MySQL or Interbase. It was quite
enjoyable, and the program has been *very* useful for managing a single
database structure on two database platforms. No more errors from hacking
two incompatible files. 

ANYHOW, to the question:

In testing, I put the database structure dictionaries in a file called, and in the program I put:

from dbstruct import *

Now I want to generalize the program so that I can pass in the name of the
Python module with the dictionary definitions along with the database type,

$ python builddb dbA mysql >dbA-mysql.sql
$ python builddb dbB ib >dbB-ib.sql

Is there some preferred way to do get Python to then do 

from dbA import * 


from dbB import *



Even if you're on the right track, you'll get run over if you just sit
- Will Rogers

More information about the Python-list mailing list