import mermaid from 'https://cdnjs.cloudflare.com/ajax/libs/mermaid/10.2.3/mermaid.esm.min.mjs'; mermaid.initialize({ startOnLoad: true });
Python standard output is different from C standard output. When Python embeds a C library which prints something on the standard output, it is difficult to catch it from Python.
See also print and cleaning and PySys_WriteStdout.
from jyquickhelper import add_notebook_menu
add_notebook_menu()
from cpyquickhelper.io import capture_output
def python_print():
print("one line")
print("two lines")
res, out, err = capture_output(python_print, lang="py")
type(out), out
(str, 'one line\ntwo lines\n')
from cpyquickhelper.io.stdchelper import cprint
def c_print():
cprint("one line")
cprint("two lines")
res, out, err = capture_output(c_print, lang="c")
type(out), out
(bytes, b'o\x00n\x00e\x00 \x00l\x00i\x00n\x00e\x00t\x00w\x00o\x00 \x00l\x00i\x00n\x00e\x00s\x00')
res, out, err = capture_output(c_print, lang="py")
type(out), out
(str, '')
On Windows, the behavior of this code is different in a standalone program probably because jupyter catches the output on his side too.
res, out, err = capture_output(python_print, lang="c")
type(out), out
one line two lines
(NoneType, None)