html code generation

Jon Clements joncle at
Thu Jan 21 00:15:01 CET 2010

On Jan 20, 10:03 pm, "D'Arcy J.M. Cain" <da... at> wrote:
> On Wed, 20 Jan 2010 21:03:10 +0000
> George Trojan <george.tro... at> wrote:
> > I need an advice on table generation. The table is essentially a fifo,
> > containing about 200 rows. The rows are inserted every few minutes or
> > so. The simplest solution is to store row data per line and write
> > directly html code:
> > line = "<tr><td>value1</td><td>value2>... </tr>"
> > each run of the program would read the previous table into a list of
> > lines, insert the first row and drop the last one, taking care of table
> > header and trailer.
> > Is there a more classy solution?
> Almost positively.  It's hard to say for sure though without knowing
> more.  However, I have a few pointers for you.
> First, think about a proper database.  You can store the raw data into
> something like PostgreSQL and then you have your historical record.
> Then you can extract and format the latest 200 records at run time.  You
> can change that value any time you want and even look at historical
> information such as the output exactly 24 hours ago.
> Whether you generate the page on demand or pre-calculate at intervals
> will depend on the ratio of updates to displays.  I would start with
> generating on demand to start with and profile usage.
> Look into server side HTML.  It can be a bit ugly generating your
> entire web page in code.  Write the static part as a regular file and
> include your small Python script to generate the table data.  The cool
> thing with that is that you can give your webaster the task of making
> pretty pages and simply deal with the variable generation.
> HTH.
> --
> D'Arcy J.M. Cain <da... at>         |  Democracy is three wolves               |  and a sheep voting on
> +1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.

I'd second this and go for a DB solution; possibly even SQLite to
start with.

I would tend to go with a web framework (maybe OTT) or a templating
engine, so if you wish, someone can do the CSS/HTML and you just
provide something that says (gimme the last 200 hundred rows). Very
similar to what D'Arcy J.M. Cain has said but should hopefully
formalise the possible problem and be applicable across the project.

Further more you might want to look into AJAX, but ummm, that's a
completely new debate :)


More information about the Python-list mailing list