Re: [cx-oracle-users] Results as dict
Brought to you by:
atuining
From: Christian K. <ckl...@no...> - 2006-11-08 15:37:01
|
Anthony Tuininga schrieb: > On 11/8/06, Christian Klinger <ckl...@no...> wrote: >> Amaury Forgeot d'Arc schrieb: >>> Christian Klinger wrote: >>>> Hello cx_oracle users, >>>> >>>> who knows a simple way to get results from a fetchall as dict´s instead >>>> of lists?? >>> You may use the cursor.description to get the column names. Something like: >>> >>> data = cur.fetchall() >>> desc = cur.description >>> dict_data = [dict((col[0], value) for col, value in zip(desc, row)) >>> for row in data] >>> >>> Hope this helps, >>> >> Helps perfect, >> >> btw other database-modules have out of the box solutions for this >> (mysql,informix) > > How do they go about this? Is that all they do or is there some switch > or some different method call that they make? > They define a additional CursorClass for this > db1 = MySQLdb.connect(user = "username", passwd="password", host= "host", db > = "database", cursorclass=MySQLdb.cursors.DictCursor) http://dustman.net/andy/python/MySQLdb_obsolete/doc/MySQLdb-4.html#usage >> thx a lot >> >> christian >> >> >> ------------------------------------------------------------------------- >> Using Tomcat but need to do more? Need to support web services, security? >> Get stuff done quickly with pre-integrated technology to make your job easier >> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo >> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 >> _______________________________________________ >> cx-oracle-users mailing list >> cx-...@li... >> https://lists.sourceforge.net/lists/listinfo/cx-oracle-users >> > > ------------------------------------------------------------------------- > Using Tomcat but need to do more? Need to support web services, security? > Get stuff done quickly with pre-integrated technology to make your job easier > Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 |