Ett exempel på lagom bra databasaccess import MySQLdb import string from constants import DB, USER, PASS, UNIX_SOCKET def _db_login(relogin = 0): """Login to the database """ global DB_CONN if relogin: DB_CONN = MySQLdb.connect(db=DB, user=USER, passwd=PASS, unix_socket=UNIX_SOCKET) return DB_CONN else: try: d = DB_CONN return d except NameError: DB_CONN = MySQLdb.connect(db=DB, user=USER, passwd=PASS, unix_socket=UNIX_SOCKET) return DB_CONN