I\'ve been using PyMySQL for a while now and created my own wrapper that I\'m used to to shorthand writing queries. Nonetheless I\'ve been creating CSV files with OrderedDi
You could use cursors.DictCursorMixin
and change its dict_type
to collections.OrderedDict (the default is dict):
from collections import OrderedDict
from pymysql.cursors import DictCursorMixin, Cursor
class OrderedDictCursor(DictCursorMixin, Cursor):
dict_type = OrderedDict
Then you can use the new cursor class as shown below
cursor = conn.cursor(OrderedDictCursor)