[Edu-sig] CP4E (states cgi demo)

Kirby Urner urnerk at qwest.net
Mon Apr 11 05:44:38 CEST 2005


So I uploaded a tiny demo showing how I might quiz myself about state
capitals using a simple cgi script.

http://www.4dsolutions.net/ocn/python/form1.txt
http://www.4dsolutions.net/ocn/python/checkanswer.txt
http://www.4dsolutions.net/ocn/python/statecapitals.txt

are viewable versions (extension changed from cgi to txt for the first two).


The executable cgi scripts are testable here:
http://www.4dsolutions.net/cgi-bin/form1.cgi

There's nothing fancy or special going on here.  Definitely Python 101
(basic basic).  But I could see incorporating this material into a Geography
class.  Again:  the server is someplace else (location, URL address) and the
infrastructure used to interact with it is global (Internet).  That's
relevant to geography!

Note that having all the capitals in a drop down makes the task easier.  You
only need to recognize the capital, not call it up from scratch.   The order
of these capitals is random (changes with every visit), not alphabetical as
one might expect from previous experience with such drop-downs.

As Anna pointed out, this same skeletal approach could fit multiple data
sets, i.e. we could reuse the code to test ourselves on any list of
key-value pairs.

I did have some big fights to get this far (typical struggles):

(1) obscure bug on first release of Python 2.4 kept cgi values from passing
to a child process.  Fixed by installing 2.4.1.  This was a bug in the
Windows version only.

(2) because I'm playing around on a WinXP laptop and using PSFTP to copy
files up to my ISP, I got bitten by the line-ending problem, i.e. Apache at
the ISP dies if the line endings are \r\n instead of \n (locally,
CGIHTTPServer didn't care).  I fixed this by running Perl stuff like:  perl
-p -e 's/\r$//' < winfile.txt > unixfile.txt

Kirby





More information about the Edu-sig mailing list