PSP Examples

Python Server Pages

Braces Test

Dave Wallace (dwallace@delanet.com) has written a module that will convert Python code that uses braces for indentation into properly whitespace indented python syntax. This is pretty nifty, and very useful for PSP.

The whitespace significance in Python syntax is difficult in PSP because HTML is the exact opposite. Whitespace doesn't matter, and neither do carriage-returns or anything else. So that makes the melding of Python and HTML a challenge.

So this is one solution.

Take out all of the whitespace significance, and just use braces.

This module allows you to use braces where you would normally be hitting <return><tab>. You can put the opening brace ({) on the line befoe the block starts, or on the first line of the block. Same kind of deal for the closing brace (}). You still need to have the colon (:) on the line right before the block starts. That's just part of Python.

To enable this funtionality in PSP, you have to set braces as the indent type for your page. So you add this directive to your PSP page:

<%@ page indentType="braces" %>

This is a little test of the functionality:

  • I'm number 1
  • I'm number 2
  • I'm number 3
  • I'm number 4
  • I'm number 5

Click on "View source" over on the left to see the source for this page.

See also the PSP documentation on braces.