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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -