Add the following code to the top of a CGI Python script to enable colorized, annotated traceback formatting whenever a fatal error occurs in your script:
import cgitb; cgitb.enable()
When in development mode, this is likely more helpful than a '500 Internal Server Error'.
cgicolorerrorsfatalimportlanguagesmodulesprogrammingpythonscripttraceback
In Python you can use the array module to quickly convert ASCII values to a string and back again.
>>> import array
>>> array.array('B', [97, 98, 99]).tostring()
'abc'
>>> array.array('B', 'abc').tolist()
[97, 98, 99]
For more information, read Python Patterns - An Optimization Anecdote.
arraysasciiconversionmodulesoptimizationpython
An essential part of any CGI written in perl that will push all the fatal errors to the browser instead of punting with the all-too-familiar 500 Internal Server error:
use CGI::Carp qw(fatalsToBrowser);
carpcgilanguagesmodulesperlprogramming
An often-used concept in shell scripting is globbing. You can use this in python, as well:
import glob
for textFile in glob.glob("*.txt"):
# Do something with 'textFile'.
globimportlanguagesmodulesprogrammingpythonshell
If you need your script to have access to ActiveRecord, ActiveMail, et al. you can place these directives at the top of your script:
#!/usr/bin/env ruby require 'rubygems' require_gem 'activesupport'
activerecordconfigurationlanguagesmodulesprogrammingrailsrorruby