Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MySql Cursor field names.
#1
HI folks.

I've seen this somewhere, but I can't find it...

I can:
cursor.execute("blah and pharp...
for row in cursor:
print row[0]
print row[1]

but how do I get to use the field names? I think it's something to do with a dictionary?

print row{'field1']
print row['field2']

Thanks.
Reply
#2
Probably. I think you can use whatever aliases you're using in the query as dict keys. When in doubt, inspect!
for row in cursor:
    print(row)
    print(dir(row))
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 607 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Cursor Variable inside Another Cursor . CX_ORacle paulo79 1 1,477 Apr-09-2022, 10:24 AM
Last Post: ibreeden
  Mysql error message: Lost connection to MySQL server during query tomtom 6 15,671 Feb-09-2022, 09:55 AM
Last Post: ibreeden
  Bug ? when dataclass field name == field type Cyril 0 1,525 Oct-22-2020, 03:26 AM
Last Post: Cyril
  Trouble retrieving dictionary from mysql.connector cursor swechsler 2 2,991 Sep-17-2019, 05:21 PM
Last Post: swechsler
  Best way to return Cursor Data rajuarien 0 1,950 Jul-29-2018, 09:47 PM
Last Post: rajuarien
  MySql and field names. MuntyScruntfundle 2 2,699 Dec-01-2017, 12:44 PM
Last Post: MuntyScruntfundle

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020