HTML parser example, anybody?
Gregoire Welraeds
greg at perceval.be
Thu May 4 11:39:47 EDT 2000
In reply to the message of Bjorn Pettersen sent on Apr 27 (see below) :
The following issue is very interesting because you can generate dynamic
contents only by using
> htmlfile = open('foo.html', 'w')
> replacements = {
> 'title': 'my title',
> 'heading': 'A Heading',
> }
> htmlfile.write( open(foo.templ).read() % replacements )
> htmlfile.close()
I got one problem left.
> <html><head><title>%(title)s</title></head>
> <body><h1>%(heading)s</h1></body></html>
What I think would be very intersting is to have the variable's name
enclosed in an HTML commentary like in the following:
<html><head><title><!--cgi: %(title)s --></title></head>
<body><h1><!--cgi: %(heading)s --></h1></body></html>
Like this, A Web designer could work on any template within an application
without any intervention of the programmer. The opposite is right too.
Any clue ? ;)
--
Life is not fair
But the root password helps
--
Gregoire Welraeds
greg at perceval.be
Perceval Development team
-------------------------------------------------------------------------------
Perceval Technologies sa/nv Tel: +32-2-6409194
Rue Tenbosch, 9 Fax: +32-2-6403154
B-1000 Brussels general information: info at perceval.net
BELGIUM technical information: helpdesk at perceval.net
URL: http://www.perceval.be/
-------------------------------------------------------------------------------
On Thu, 27 Apr 2000, Bjorn Pettersen wrote:
> Date: Thu, 27 Apr 2000 13:10:21 -0600
> From: Bjorn Pettersen <bjorn at roguewave.com>
> To: Gerhard Haering <haering at sunhalle8.informatik.tu-muenchen.de>
> Cc: python-list at python.org
> Subject: Re: HTML parser example, anybody?
>
> Gerhard Haering wrote:
> >
> > Hi!
> >
> > I want to transform my own HTML templates (with a few template tags,
> > special comments, and so on) into final HTML for the browser. I would like
> > to use Pyhton's htmllib, but from the docs I can get no clue on how to get
> > it done. I seem to have to use a writer and a formatter class ...
> >
> > I would greatly appreciate an example of HTML -> HTML using
> > htmllib/sgmllib. Can anybody provide pointers/code snippets?
>
> Why don't you just use Python's string syntax, e.g. if you have the
> following in a template file called foo.templ:
>
> <html><head><title>%(title)s</title></head>
> <body><h1>%(heading)s</h1></body></html>
>
> you can do something like:
>
> htmlfile = open('foo.html', 'w')
> replacements = {
> 'title': 'my title',
> 'heading': 'A Heading',
> }
> htmlfile.write( open(foo.templ).read() % replacements )
> htmlfile.close()
>
> -- bjorn
>
> --
> http://www.python.org/mailman/listinfo/python-list
>
>
More information about the Python-list
mailing list