You can intercept stdoutbefore writing from your code C, and then process the output value.
import sys
import StringIO
buffer = StringIO.StringIO()
sys.stdout = buffer
sys.stdout = sys.__stdout__
C, printf - , .
, , byref a c_char_p, C, , Python. ( ctypes free).