Giter VIP home page Giter VIP logo

Comments (4)

GoogleCodeExporter avatar GoogleCodeExporter commented on July 18, 2024
Also sorry I should have made it an enhancement request instead of it being an 
issue

Original comment by [email protected] on 6 Jan 2012 at 4:21

from prettytable.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 18, 2024
Hi there,

Thanks for this suggestion.  Sorry for my late response.

Do you mean you just want to be able to specify a function that is then passed 
to list.sort with the key= parameter?  If so, I think that should be pretty 
easy and I'll have a go at implementing it soon.

Cheers,
Luke

Original comment by [email protected] on 23 Mar 2012 at 3:52

  • Changed state: Accepted
  • Added labels: Type-Enhancement
  • Removed labels: Type-Defect

from prettytable.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 18, 2024
Okay, I have now committed a change to trunk which allows you to do:

MyTable.sort_key = foo

to use an arbitrary sort key function.  I would appreciate it if you could give 
this a test and let me know how it works out in your particular use case.  
Please note that if you are currently using PrettyTable 0.5, there has been an 
API change between that version and the version currently in trunk.  Read the 
Wiki article at http://code.google.com/p/prettytable/wiki/Tutorial06 for an 
overview of the changes involved.

Also, be aware that the .sort_key setting will interact with the .sortby 
setting.  Firstly, PrettyTable will do no sorting at all unless .sortby is set 
to a valid fieldname.  Also, note that the sort key function will be passed 
lists, with the following format:

[sortby_col, col1, col2, col3,...]

Each list corresponds to one row of the table.  The first element in the list 
is that row's value for the column which is being sorted by, and the subsequent 
values are the values for each column, in order, *including a repetition of the 
column being sorted by*.  This is because of the way that PrettyTable uses the 
Decorte-Sort-Undecorate paradim internally.  It's possible that I'll rewrite 
this in future to be a bit cleaner, but for now you'll just have to be careful!

Original comment by [email protected] on 24 Mar 2012 at 7:26

from prettytable.

GoogleCodeExporter avatar GoogleCodeExporter commented on July 18, 2024
Given lack of negative feedback about this change for over one month, I am now 
closing the issue as "Fixed".  If the current implementation of sort key 
function setting turns out to have shortcomings, people should feel free to 
submit a new Issue.

Original comment by [email protected] on 30 Apr 2012 at 7:03

  • Changed state: Fixed

from prettytable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.