S
Steve Holden
Lawrence said:
Can you please stop this incessant carping? c.l.py used to be a fun
place to hang out.
regards
Steve
Lawrence said:
This is a spectacularly bad (non-)solution to the original problem. ItLawrence said:Pom wrote: said:I want to convert a Mysql resulset to a dictionary.
Here's a function that does this one row at a time:
def GetEachRecord(TableName, Fields, Condition, Values, Extra = "") :
"""generator which does an SQL query which can return 0 or more
result rows, yielding each record in turn as a mapping from
field name to field value. TableName can be a single table name,
or a comma-separated list of names for a join. Extra allows
specification of order/group clauses."""
Cursor = sql.conn.cursor() # modify this as appropriate
Cursor.execute \
(
", ".join(Fields)
+
" from "
+
TableName
+
" where "
+
Condition
+
" "
+
Extra,
Values
)
while True :
NextRow = Cursor.fetchone()
if NextRow == None :
Cursor.close()
raise StopIteration
#end if
yield dict(zip(Fields, NextRow))
#end while
#end GetEachRecord
You'd use this something like
for Link in GetEachRecord(...) :
... Link[fieldname] ... blah-blah ...
Steve said:Can you please stop this incessant carping? c.l.py used to be a fun
place to hang out.
Frank said:I am reminded of a spoof Latin motto from the days of my youth -
NIL ILLEGITIMO CARBORUNDUM
Fredrik said:isn't that usually written
Illegitimi non carborundum
?
or is that just due to differences between british latin and american latin ?
</F>
isn't that usually written
Illegitimi non carborundum
or is that just due to differences between british latin and
american latin ?
isn't that usually written
Illegitimi non carborundum
or is that just due to differences between british latin and american latin ?
You were lucky, you *had* a youth [... etc.]Frank said:or my bad memory - my youth was a long time ago![]()
Something I had to double check first -- as MySQLdb already has athe OP didn't ask for a field name => value mapping, though.
American Latin? Is that Lingua::Romana:erligata?
I suppose you are using a generator to avoid data duplication, but for
100,000 records this could be regarded as a premature optimisation on
modern computers.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.