# a sort of lightweight read-only ORM

# the recordtype fields must match exactly the DB fields (see below how to obtain them)!
Identif = recordtype("Identif", "Protein ID tech")

Identif.__str__ = lambda self: self.Protein

def read_db(db, limit=0):

    db = MySQLdb.connect(..., db=db, cursorclass=MySQLdb.cursors.DictCursor)
    cursor = db.cursor()
    if limit > 0:
        limit = " LIMIT %d" % limit
    else:
        limit = ""
    # end if
    cursor.execute("SELECT ID, Protein, tech FROM IDs" + limit)
    result = cursor.fetchall()

    res = {}
    for row in result:
        #print r.keys() for getting the field names to be specified in the recordtype
        res[row['ID']] = Identif(**row) # "**" transforms the parameters into a dictionary
    # end for
    db.close()

    return res

# end def read_db

# now use

prots = read_db("Proteins")
prots['id1'].Protein