python redirect sys stdout to string