[Edu-sig] CGI with string.Template

kirby urner kirby.urner at gmail.com
Fri Jun 8 20:17:15 CEST 2007

I've heard talk of retiring the string module but have a hard time
believing it, given the potential of Template to make things easier
for some of us.  Just because all methods of the float type may
be accessed using dot notation doesn't mean we want to get rid
of 'import math'.  Think of 'import string' as 'import math' for type
str ( str instead of float, or cmath instead of math for type(1j)).

Anyway, below I've appended a little script I wrote to keep
my foot in the door once a scholarship became available (my
company is private for-profit, looks at scholarships as
accounts receivable for my skills as a teacher, consultant or
whatever, for which DWA bills me out at a handsome rate
(or so I like to suppose)).

The more formal paper came later, once more details emerged.
The Abstract was the last puzzle piece to fall in to place:

Cutting and pasting from the PDF (sorry that doesn't look good):


My paper for EuroPython 2005 explored what I call Pythonic
Mathematics, a way of presenting pre-computer analytical content
within the OO paradigm, including pre-college.1 This thinking informed
my participation in Shuttleworth Foundation planning meetings and my
presentation to the London Knowledge Lab in the following year.2 This
year, I'm delving yet more deeply into Pythonic Math, while also
weaving in some more cultural threads, especially the "design science"
thread with its geodesic spheres and other graphical content, the
theme of my OSCON 2005 presentation.3 I've been field testing these
combinations in my home town of Portland, through a school called
Saturday Academy.4 Whereas Guido named Python for Monty Python,
begetting allusions which aren't going to go away, there's more we
might do to make our snake come across as charming and smooth, not too
slimy or oily (negative attributes customarily associated with snakes
by the more snake-unfriendly).5

I'm down to hammering out details with local hoteliers at this
point, may have lost the LOT flight (no one said anything bad
about Warsaw, when I made inquiries on the EuroPython list
-- there's a flight from Chicago).

What I'll do for the talk is run Python's native itty bitty server
and not depend on the Internet, and only for a little of the demo.

I have my own expensive small travel projector, which I won't
want to blow by giving it a wrong voltage, so I'm still stressing
about adapters, transformers and what not.  Maybe bringing
the projector is a bad idea...

My patter might be less about the code below, which is very simple
and I'm not trying to be condescending, and more about how
we might rank ISPs in terms of Python friendliness.

It's already a minority of ISPs who allow account-owner script
writers to run processes via ssh (considered a "geek level" task
-- hardly, in and of itself).  Of these, some keep a dusty old
Python lying around, perhaps a 1.x, and think that ought be
just fine fine.  No string.Template.  No lots of kwel stuff.  So
a first criterion for defining an ISP as Python-friendly might be:
having a fairly current Python in /usr/bin or whatever, available
to would-be scripters.

Here's an example of an ISP that knows how to sound Python
friendly (and I think they're quite sincere):
(not my ISP by the way, I have no known financial ties to
this company (yet anyway)).




#       Paper and .py module for Europython
#           by Kirby Urner, 4D Solutions
#                    May 29, 2007

# If you run this in Python, you'll get my paper with a
# two paragraph abstract.  If you run it again, you'll
# get the same abstract, with the other paragraphs
# reordered.

# The primitive paragraph sequencer below suggests
# a non-linear network for a model i.e. one that
# "connects around in all circumferential directions"
# (Fuller) as hypertext (http).

# My Pythonic hypertoons take similar approach, but
# with multiple passes through each node and more
# clearly defined "edges" connecting them.  Instead
# of paragraphs, I've used geometric transitions in
# VPython. I'd be happy to talk about these in a demo.

# http://video.google.com/videosearch?q=hypertoons&hl=en

# Shall I attach a bibliography of mostly URLs?

import sys
import cgitb; cgitb.enable()

from random import shuffle
from string import Template

sys.stderr = sys.stdout

webpage = Template(
"""Content-Type: text/html

<head><title>EuroPython Proposal</title></head>
<table align="center" width="550">
<div align="center">

<em>Abstract</em>:<br />

<hr />



nodeA = """
CP4E or Computer Programming for Everybody was
Guido van Rossum's attempt to harness the power
of Python to best advantage:  let's use the charm
of our snake to recruit more people into the
circle of "knows how to program".  Python isn't
the only language suitable for CP4E work.  The
more the merrier in some ways, with Python always
there as a potential glue language."""

nodeB = """
I came to Python as a former math teacher and
career programmer, looking for ways to explore
geometry.  These were the early days of the Net
and few Polyhedra were available, even as GIFs
or JPEGs, let alone in VRML or as yet not
invented X3D.  I started in xBase with Visual
FoxPro, then moved to Java then Python in short
order.  Python has been my top drawer language
for geometry studies ever since."""

nodeC = """
Teachers are struggling with the puzzle of how
to incorporate computing machines within a
traditional curriculum inherited from times
when "computers" were human beings, tasked
with doing figures, quickly and accurately --
a clerical task.  The schools were designed to
mass produce future "computers" of the human
variety.  Then came many leaps in technology,
and yet we're still stuck with much the same
training in the early years.  We waste students'

nodeD = """
South Africa is one of those places where the
disparity between have and have-not is huge, and
education has no credibility unless it shows very
clearly how it's designed to close that gap,
including the so-called 'digital divide.'  The
Shuttleworth Foundation, in collaboration with
others in the public and private sector, is
prototyping Kusasa, a curriculum designed to
teach mastery over the process of learning to
use tools, including but not limited to computers."""

nodeE = """
The dream of giving each child access to powerful
computing and communications devices, able to
access the world's libraries, has bubbled to the
surface again in the form of Negroponte of MIT's
One Laptop per Child (OLPC) initiative.  Alan Kay
of SmallTalk fame has been another subscriber to
this "Dynabook" vision and was present at a summit
meeting in London, hosted by Mark Shuttleworth,
designed to get Kusasa going.  Guido van Rossum
and myself came from the Python community.  Others
represented the South African government, academia,
and other CP4E computer languages."""

nodeF = """
Not being a resident or citizen of South Africa,
I've been working on a CP4E project in Portland,
via Saturday Academy, to teach about the culture
of open source collaboration, design science,
and positive futurism.  I draw from Guido's work,
plus acknowledge Kenneth Iverson of APL fame as
a major influence (he later gave us the J language
in collaboration with Roger Hui and his son).
I came away from the summit in London hoping to
prototype Kusasa-like content in Oregon.  I've
been pretty successful in doing that."""

nodeG = """
Per my presentations at OSCON and EuroPython in
2005, I'm influenced by the Buckminster Fuller
syllabus, a branch of American Transcendentalist
literature.  As a philosophy guy from Princeton,
with a thesis on Wittgenstein, it was natural for
me to look for contemporary philosophers and to
study their work.  This led me into Fuller's
network and subsequent geometry studies, around
the same time as I got a math teaching job at
St. Dominic Academy in Jersey City, NJ.  Although
I later switched careers, I never lost my interest
in this geometry, hence my search for a good
computer language with which to pursue my studies."""

nodeH = """
OSCON, Pycons, and most recently Portland Barcamp
have also taught me a lot, about geek culture and
its collaboration tools.  By working together, I
think we can keep OLPC and CP4E in good working
order, achieving positive results for people around
the world.  If you happen to be lucky enough to be
using Python, then we already have many ideas on
which you might build, to make teaching (including
peer teaching) a potentially important and relevant
part of your career.  This is the subject of my talk."""

nodes = [nodeA, nodeB, nodeC, nodeD, nodeE, nodeF, nodeG, nodeH]

abstract = "<p>%s</p>\n<p>%s</p>" % (nodeA, nodeH)


title = """
Paper and .py module for Europython 2007<br />
by Kirby Urner, 4D Solutions<br />
May 29, 2007<br /><br />"""

pagedict = {"Para0":nodes[0],

print webpage.substitute(pagedict)


Note subtle "bug" but I've decided to keep it:  only five lucky paragraphs
make the "top five" and get web served.  The rest don't make the cut --
unless the user reloads, then maybe.  A "reward" for those that do.

More information about the Edu-sig mailing list