getting database column names from query

2006-08-16 Thread Jason Nordwick
I'm using MySQLdb and can connect and issue queries that return result sets, but I how do I get the column names for those result sets? >>> c = MySQLdb.connect(*creds) >>> k = c.cursor() >>> k.execute("select * from account") 3L >>> k.fetchall() ((1L, 'test', -1L), (2L, 'Test', -1L), (3L, 'Test2'

Re: yet another noob question

2006-08-15 Thread Jason Nordwick
(joins are merely indexes into other structures). -j Steve Holden wrote: > Jason Nordwick wrote: >> I use reduce to also do indexing, hashing with upsert semantics of lists of >> key-value pairs, transitioning through a state table, etc... >> >> Somebody else poin

Re: yet another noob question

2006-08-15 Thread Jason Nordwick
t timing reduce against a hand coded loop, but instead the operator '+' against the function add, as the function symbol lookup and call seem to have a heavy price. Reduce was one of the nice ways to eliminate some of those lookups. -j [EMAIL PROTECTED] wrote: > Jason N

Re: yet another noob question

2006-08-14 Thread Jason Nordwick
opadd(v): sum = 0 for x in v: sum = add(sum, x) return sum (Yes, I know there are better ways to sum up a list, but I just wanted to test the performance of the loop against reduce. In most of my reduce usages, the function passed to reduce is much mor

Re: yet another noob question

2006-08-14 Thread Jason Nordwick
Stargaming wrote: > > Also note that reduce will be removed in Python 3000. What will replace it? -j -- http://mail.python.org/mailman/listinfo/python-list

Re: yet another noob question

2006-08-14 Thread Jason Nordwick
Somehow my other response to the list got lost. I'm still learning Python, but this seems much better than my first attempt: def pr(x): print x def cross(x,y): return [a+b for a in x for b in y] x=map(pr, reduce(cross, [map(str,range(1,6))]*5)) -j Stargaming wrote: > Jason Nordwick

Re: yet another noob question

2006-08-13 Thread Jason Nordwick
better (sorry, still learning Python): def cross(x,y): return [a+b for a in x for y in b] Jason Nordwick wrote: > Or without filter: > > from operator import add > def pr(x): print x > def cross(x,y): return reduce(add, [[a+b for b in y] for a in x]) > x=map(pr, reduce(cross,

Re: yet another noob question

2006-08-13 Thread Jason Nordwick
Or without filter: from operator import add def pr(x): print x def cross(x,y): return reduce(add, [[a+b for b in y] for a in x]) x=map(pr, reduce(cross, [map(str,range(1,6))]*5)) mike_wilson1333 wrote: > I would like to generate every unique combination of numbers 1-5 in a 5 > digit number and

Re: yet another noob question

2006-08-13 Thread Jason Nordwick
def pr(x): print(x) >>> x=map(pr,[x for x in xrange(11,56) if '1'<=min(str(x)) and >>> max(str(x))<='5']) 11 12 13 14 15 21 22 23 24 25 31 32 33 34 35 41 42 43 44 45 51 52 53 54 55 mike_wilson1333 wrote: > I would like to generate every unique combination of numbers 1-5 in a 5 > digit number an

Re: Recurse Directories and process files in directory

2006-08-12 Thread Jason Nordwick
Use os.system to execute a string and os.walk to get a recursive list of files >>> def processdir(curdir,subdirs,files): ... map(lambda f:os.system('\\cygwin\\bin\\wc -l "%s"' % f), [curdir+os.sep+x for x in files]) ... >>> map(lambda x:processdir(*x), os.walk('\\dev\qclient')); 6 \dev\qclie

Re: trouble with replace

2006-08-12 Thread Jason Nordwick
>>> pats = ['abcdef', 'defgef', 'effwer'] >>> reps = ['highway', 'news', 'monitor'] >>> s = 'defgefabcdefy\n\n\n effwerbyuuuterrfr' >>> reduce(lambda x,y: x.replace(*y), zip(pats,reps), s) 'newshighwayy\n\n\n monitorbyuuuterrfr' f pemberton wrote: > I have a string (xdata) and theres a