A flexible main()

by Guido van Rossum
http://www.artima.com/weblogs/viewpost.jsp?thread=4829

with some minor modifications.