[Tutor] simple report writing?

Liam Clarke-Hutchinson Liam.Clarke-Hutchinson at business.govt.nz
Mon Nov 7 20:45:53 CET 2005

Hi RC, 

>I have a list (x_list) of class data.

So, a list of instances/classes then.

You'll have to pass a custom function.

def tSort(objA,objB):
    #assuming that objA.x & objB.x are the items to sort by, and are
    if objA < objB:
        result = -1
    elif objA = objB:
        result = 0
    elif objA > objB:
        #Would normally just do as an else
        #But being ultra explicit
        result = 1

    return result


Liam Clarke

-----Original Message-----
From: tutor-bounces at python.org [mailto:tutor-bounces at python.org] On Behalf
Of CPIM Ronin
Sent: Tuesday, 8 November 2005 8:11 a.m.
To: tutor at python.org
Subject: [Tutor] simple report writing?

I have a list (x_list) of class data. How do I sort that list by a selected 
variable common to all members of the list?

x_list.sort(key=x_list.v_name) # doesn't work becuase x_list can't see the 
individual items.


Don't just search. Find. Check out the new MSN Search! 

A new monthly electronic newsletter covering all aspects of MED's work is now available.  Subscribers can choose to receive news from any or all of seven categories, free of charge: Growth and Innovation, Strategic Directions, Energy and Resources, Business News, ICT, Consumer Issues and Tourism.  See http://news.business.govt.nz for more details.

http://www.govt.nz - connecting you to New Zealand central & local government services

Any opinions expressed in this message are not necessarily those of the Ministry of Economic Development. This message and any files transmitted with it are confidential and solely for the use of the intended recipient. If you are not the intended recipient or the person responsible for delivery to the intended recipient, be advised that you have received this message in error and that any use is strictly prohibited. Please contact the sender and delete the message and any attachment from your computer.

More information about the Tutor mailing list