The main advantage of StringIO is that it can be used where a file was expected. So you can do for example (for Python 2):
import sys
import StringIO
out = StringIO.StringIO()
sys.stdout = out
print "hi, I'm going out"
sys.stdout = sys.__stdout__
print out.getvalue()