[Tutor] implementing a table data structure in python?

Thomas Clive Richards thomi at imail.net.nz
Tue Dec 21 07:43:22 CET 2004


Hi,

I'm trying to implement a reasonably efficient table data structure, but ith a 
few quirks...

The application I'm building is a CGI program which allows users to view a 
large table of data. In addition, users can restrict the data shown. Some 
sample data might look like this: (note you'll need a fixed width font for 
this)

D       x    y    z   val   q
-------------------------------------
1    |  1    2    3   23    0.1
13   |  2    3    4   24    0.15
24   |  1    1    2   12    0.2
45   |  2    3    5   1     0.12
116  |  6    2    7   27    0.18
211  |  9    4    6   28    0.45

Actually, the real data I'm using is very different - but this is easy to 
type :)

The entire table is stored in a plain text file, and could contain up to 500 
KB of data.

Every time my CGI script is run, it must read this file from disk, and return 
a 2D array of values; However, I need to be able to restrict the columns 
shown.

For example, user A might not want to see the D & val columns - I need a way 
of trimming these easily..


Normally I'd use a database like mysql, postgreSQL, or even SQLite for this 
sort of application, but the server I'm working on (which is outside my 
control) does not have any of these installed.

The CGI will not see heavy use, and I'm not very worried about race conditions 
or collisions...


Does anyone have any advice for me? implementing this as a simple 2D array (or 
list of lists) seems a little silly - surely there's a better way?


Actually, python bindings to the STL (or something similar) would be useful in 
many situations....



Thanks,
-- 

Thomi Richards,
thomi at once.net.nz


More information about the Tutor mailing list