Python module to capture stdout and/or stderr