<br><br><div><span class="gmail_quote">On 7/19/05, <b class="gmail_sendername">Kent Johnson</b> <<a href="mailto:kent37@tds.net">kent37@tds.net</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Luis N wrote:<br>> I'd appreciate some comments on my use of globals and the map function.<br>><br>> import metakit<br>> import marshal<br>><br>> db = metakit.storage('<a href="http://addy.mk">addy.mk</a>
<<a href="http://addy.mk">http://addy.mk</a>>',1)<br>> dbs = db.getas('dbs[db:S,marshal:B]')<br>><br>> def li(i):<br>> i = i[:-2]<br>> return i<br>><br>> def selectDB(f):<br>> if
f.has_key('db'):<br>> d = []<br>> d['db'] = f.get('db').value<br><br>The above line is not valid Python; list indices must be integers</blockquote><br>
> id = dbs.find(d)<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">> if id != -1:<br>> global desc, vw, primaryKey<br>> desc =
marshal.loads(dbs[id].marshal)<br>> vw = db.getas('%s%s' % (dbs[id].db,desc))<br>> desc = map(li,desc)<br><br>This
use of map seems fine to me. You could also write it as a list
comprehension which is more mainstream Python idiom and maybe more
readable in this case as it is self-contained:<br> desc = [ i[:-2] for i in desc ]<br><br>> primaryKey = desc[0]<br>> return desc, vw, primaryKey<br><br>I
don't see the need for the global declaration; desc, vw, primaryKey are
all assigned within this function and returned to the caller.</blockquote><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Kent</blockquote>
<div><br>
<br>
My blooper, should be d={} <br>
<br>
In this case consider desc, vw, and primaryKey to be of the same
importance as dbs, other functions must access them in a way that
renders their being local impossible, unless the logic where to be
encapsulated in a class, which didn't seem necessary.<br>
</div><br></div><br>