Ask Your Question

# Revision history [back]

I'll attempt to recreate my original answer here; I'm not sure what happened to the old one. I tried your example code in SageMathCell and it works fine (as I previously suggested however there is no need for modifying sys.path).

The problem seems to have something to do with how SageMathCell handles standard output. I noticed this after trying: print(sys.__stdout__) in SMC, and that returns: <log.StdLog object at 0x7f68d71cbb50>.

I don't know exactly how SMC works, but that seems to indicate that Python's normal stdout is being replaced with some object that logs stdout at the Python level. However, when you compile C code containing printf()s, that outputs at the C level, but I suspect SMC is not capturing that, and is only capturing prints from Python by overriding sys.__stdout__. I would consider this a bug in SMC, as it should be able to capture output to the stdout file descriptor, but it appears it does not.