Comments (4)
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.
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.
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.
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)
- the data on "how to display chinese character"
- how to display "ambiguous" width in chinese character?
- table.min_width is broken when using PLAIN_COLUMNS style HOT 2
- Field alignment error when using "blessings" module HOT 1
- Adding colors to column values messes up the spacing HOT 2
- Setting float_format in **kwargs does not actually affect output - confusing behavior HOT 1
- Permissions are incorrect HOT 1
- Add date formatting for datetime etc instances HOT 3
- In get_string, end is eval before sortby
- HTML output is lacking borders, alignment
- Cannot print unicode characters, for example: degree symbol °
- Pandas DataFrame Table Factory HOT 3
- Upload new version to pypi
- xterm reset escape sequence not filtered HOT 2
- Support large tables in output HOT 1
- Prettytable 0.7.2 does not handle rowspan correctly
- Creating a PrettyTable inside a for. HOT 1
- Project Future and Plans HOT 5
- Export project to Github (or other git hosting project) HOT 2
- Stretching columns when the data are longer than the header
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from prettytable.