[Tutor] handling of tabular data

Alan Gauld ukc802591034 at btconnect.com
Sun Oct 9 01:45:22 CEST 2005


> with the little I know about classes, I assume that then I would have
> a list of class instances as representation of my tabular data
> but given such a list of class instances, i would still need for
> loops to get to e.g. the minimal value of a certain attribute in all
> classes in that list. OR?

OR you could define class level member for the stats and have the
constructors update those values at instance creation time.

A very simple totaling example:

class Number:
     total = 0
     def __init__(self, n):
        self.value = n
        Number.total += n
     def __del__(self):
         Number.total -= self.value

# now create some instances:
numbers = []
for n in range(10):
    numbers.append(Number(n))
print Number.total

> and what would be the benefit of using classes then?

Actually not that much for this kind of app and personally
I rarely use OOP for MIS type functions, SQL is usually
more powerful, either direct;ly or mixed with a scripting
language like Python. But if the class could be used for
other functions within the application - ie MIS was only
one aspect - then classes could be a very useful single
mechanism to crack both problems in one go.

HTH,

-- 
Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld







More information about the Tutor mailing list