Newbie Q: Import code at run-time?

James Knowles jamesk at ifm-services.com
Mon Feb 25 07:43:07 CET 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
dbstruct.py, 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,
e.g.

$ 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 * 

and 

from dbB import *

?

Thanks!



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



More information about the Python-list mailing list