DB-API: how can I find the column names in a cursor?

A.M alanalan at newsgroup.nospam
Thu Jun 1 08:11:32 EDT 2006


Hi



I use a code similar to this to retrieve data from Oracle database:



import cx_Oracle



con = cx_Oracle.connect("me/secret at tns")

cur = con.cursor()

outcur = con.cursor()

cur.execute("""

     BEGIN

         MyPkg.MyProc(:cur);

     END;""", cur=outcur)



for row in out_cur:

     print row





The problem is I don't know how to find out what are the column name and 
type that comes out of query (each row in cursor).



Is there any possibility that my Python code can find out the column name 
and type in each row in cursor?



The other problem is accessing data in each row by column name. In Ruby I 
can say:



Print row["ColName"]



In Python; however, I must access to row contents by integer index, like 
PRINT ROW[0], which reduces my program's readability.



Can I access to row's contents by column name?



Any help would be appreciated,

Alan





More information about the Python-list mailing list