#!/usr/bin/env python
# -*- coding: utf-8 -*-
from sqlalchemy import create_engine
connection = create_engine('mysql://user:passwd@localhost:3306/db').connect()
result = connection.execute("select * from table")
for v in result:
print v['id']
print v['name']
connection.close()
how i can get TABLES COLUMNS NAMES dynamically? in this case id
and name
something like this
headers=[ i[0] for i in result.cursor.description ]
same question here return column names from pyodbc execute() statement
You can either find the columns by calling
result.keys()
or you can access them through callingv.keys()
inside thefor
loop.Here's an example using
items()
: