Explicitly close files rather than relying on garbage collection

Avoids Python 3.2’s ResourceWarning.
Miscellaneous name changes anticipating Python 3

* Inspired using “2to3”
* functools.reduce, io.StringIO new names
* cPickle removed
Cannot use wildcard “import *” in function scope in Python 3