%%cython
from libc.stdio cimport printf
def test():
printf('abc')
If I run test()
, it doesn't print anything.
Currently I am doing something stupid as:
cdef char s[80]
sprintf(s, 'something')
print s
What's a better way to use printf
in cython? Why doesn't it print?
You can use the wurlitzer
package to capture C-level stdout / stderr and redirect it to IPython.
For example, include the following code blocks in your Jupyter notebook:
%load_ext Cython
%load_ext wurlitzer
%%cython
from libc.stdio cimport printf
def test():
printf('abc')
test()
# prints "abc"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With