Castalian
General notes on embedding Python code in Castalian pages
One important difference between Castalian and Active Server Pages is that
ASP supports HTML embedded in code
blocks1:
<% for a = 1 to 10 %>
This is row <%= a %>
<% next %>
Castalian doesn't support this. The reason is that Python code isn't
amenable to this sort of behaviour; because Python blocks code by
indentation, you'd have to block your HTML code appropriately, which would
be unpleasant. It's possible to have this work, but it would be unintuitive
and weird. If there are any good solutions for this, I'd like to hear them.
Meanwhile, to do this, you have to use response.write statements
to print your HTML. This may be made easier by Python's triple-quote support,
so you can say
response.write("""Here's a line of HTML.
And here's a <b>bold line</b>.
""")
Python code in Castalian pages, as may be obvious from the examples, is blocked off by <?cas and ?> markers. This may conflict with PHP in its "use <? and ?>" mode.
Note that you can display a variable with <?cas=varname?>, which will substitute the value of varname for the directive. However, there must not be spaces around the varname, because the Python interpreter will take them as indentation and complain.
1. Although having Python code embedded in an ASP page, as supported by IIS, doesn't allow it either, for much the same reason that Castalian doesn't. [back]