Stop using print(), pass around an explicit file-like object

This allows getting rid of the sys.stdout hack in tests.
get rid of the [] placeholder arg