[Tutor] globals and map()

Luis N tegmine at gmail.com
Tue Jul 19 10:16:03 CEST 2005

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 <http://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 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050719/d34825f0/attachment.htm

More information about the Tutor mailing list