quetz-mod_python-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Neo Eureka <...@https.ru>
Subject Re[2]: PSP opinion?
Date Sun, 25 May 2003 09:28:54 GMT


  To start from beginning :) it seems like the most clever solution to
all of this is not to try to embed Python code in HTML since:

-- there are many templating systems, and if one doesn't like any of
   them he/she can easily write a new one (like I did);

-- Python is not a "language for everyone" anyway, if they like a
   "vinaigrette" from HTML and code they have PHP and such ready for

   See below...

> To start from beginning - here are two things that I think are important,
> and you will probably agree with this.

> 1. That Python semantics do not carry into HTML. HTML ignores whitespace,
> and we shouldn't interfere with that.

> 2. That no 3rd language is invented (this is the problem with pretty much
> all of the existing Python-in-HTML solutions). Knowledge of Python and
> HTML should be sufficient, the rest should just be "obvious".

> I think we're doing well on (2), but (1) is problematic.

> The problem with (1) is obivously how do you denote blocks of HTML without
> it being indented.

> We've got the "{". There is a problem with it though:

> <%
> if (size == "big"):

>         # some code

>         if (color == "red"): {

> <h1>Do we have a big red dog?</h1>

> Looking at the above, it would seem that the HTML should be printed only
> if (color == "red"), but the lexer has no way of knowing that the "{"
> denotes two indents. I really don't know how to solve this.

> Another problem with the "{" is that it makes an assumption that the
> indent is a tab. Pytho is smart about indents and can "learn" the indent
> you're using - at least emacs converts all tabs to spaces, some people use
> two spaces, some use three (I like 4), and this could be a source of
> syntax errors.

> The third problem with "{" of course is that it has other meaning within
> Python.

> As I was driving home just now I thought of another rather clever (IMO)
> option:

> <%
> if (size == "big"):
>         if (color == "red"):
>                 # beginning of block

> <h1>This dog is big and red - it's Clifford!</h1>

> So the rule is basically that the last indent of the Python code would
> carry into following HTML.  (the text after # doesn't matter, and in fact
> it could also be any other statement, e.g. "pass", but using a descriptive
> comment would be a good practice).  You could end blocks by specifying
> more comments:

> <%
>         # end of block
> <h1>This dog is big but not red.</h1>

> The lovely thing about this is that it's 100% Python compliant and very
> easy to implement.

> How about it?

  Grisha, it's 100% Python compliant except one small thing -
"significant" comments.

  Look at what is going on - the language itself resists to what you
are trying to do with it!

> Grisha

Neo Eureka / mailto:neo@https.ru

View raw message