how to parametrize python sorting -
i have following code in python sorting
cursor.execute('select column1, column2, column3 table1'); details = cursor.fetchall() def mixed_order(details): return (details.column1, details.column2, details.column3 ) sorted_details = sorted(details,key=mixed_order)
i want parameterize mixed_order function saying
criteria1 ="details.column2" criteria2 ="details.column1" criteria3 ="details.column3"
and define following
def mixed_order(details): return (criteria1, criteria2, criteria3 )
but, python not sorting details. wrong in way defined criteria's , assign columns it.
i think want this:
def mixed_order(details): return (getattr(details, criteria1), getattr(details, criteria2), getattr(details, criteria3) )
Comments
Post a Comment