I'd appreciate some comments on my use of globals and the map function. The idea here is that (simple) Metakit database definitions can be loaded dynamically from another Metakit database detifintion. (Yes this would likely be easier with a SQL database, don't ask!) Nasty code ahead:

import metakit
import marshal

db = metakit.storage('addy.mk',1)
dbs = db.getas('dbs[db:S,marshal:B]')

def li(i):
    i = i[:-2]
    return i

def selectDB(f):
    if f.has_key('db'):
        d = []
        d['db'] = f.get('db').value
        id = dbs.find(d)
        if id != -1:
            global desc, vw, primaryKey
            desc = marshal.loads(dbs[id].marshal)          
            vw = db.getas('%s%s' % (dbs[id].db,desc))
            desc = map(li,desc)
            primaryKey = desc[0]            
            return desc, vw, primaryKey      
        else:
            error(-1)           
    else:
        error(select=None) 
_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to