CGI with Python: advantages?

Paul Schreiber paul at magic.ca
Sun Aug 6 15:06:33 EDT 2000


I missed the beginning of this thread, but I'll jump in anyway.

One thing that drives me nuts about Python is that you can't reference 
undefined variables or undefined keys in a dictionary.

I end up with lines like:
   whatever = 0

and:
   eggs = { 'something' : '', 'etc': '' }

at the top of my code, just to prevent KeyError exceptions.

Now, the hardcore CS types will probably tell me that allowing the 
introduction of arbitrary variables into the namespace is bad, 
introduces errors and makes it harder to prove correctness (ha!).

But damnit, it's really useful for web programming.

My second pet peeve is that:
   import cgi
   form = cgi.FieldStorage()
   print 'hi %s' % form['name'].value

is much more awkward than:
   print "hi $name";

The reason this is an issue is that web forms don't always have all the 
fields submitted, and this requires extra work in python.

   if form.has_key('checked'):
     checked = form['checked'].value

versus:
   $checked

I prefer PHP for doing web pages. It's designed explicitly for that 
task, and it's much faster since it's compiled into Apache. And it has 
the nifty Zend optimizer.

Recall that I didn't say I disliked python. I like it very much. I use 
it every day. Just not for web pages.

Paul



More information about the Python-list mailing list