Import if condition is correct

Steve Holden steve at
Sat Oct 28 14:07:39 CEST 2006

MindClass wrote:
> Steve Holden wrote:
>>I'm guessing that you think this might be necessary to avoid importing
>>the same module multiple times: it's not. Python only runs the module's
>>code the first time the module is imported into a program. A further
>>import statement effectively does noting, because the interpreter sees
>>(from an entry in the sys.modules dictionary) that the module is already
> The problem is that I've to import different libraries according to the
> ORM (SQLObject, SQLAlchemy, etc)
So why the need for global variables?

if MySQL_wanted:
     import MySQLdb as db
elif sqlite_wanted:
     import pysqlite as db
     import psycopg2 as db

conn = db.connect(...)

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Skype: holdenweb
Recent Ramblings

More information about the Python-list mailing list