%%cython
from libc.stdio cimport printf
def test():
printf('abc')
如果我运行
test()
,它不会打印任何内容。目前我做的事情很愚蠢,就像这样:
cdef char s[80]
sprintf(s, 'something')
print s
在Cython中,如何更好地使用printf
函数?为什么它没有输出?
%%cython
from libc.stdio cimport printf
def test():
printf('abc')
test()
,它不会打印任何内容。cdef char s[80]
sprintf(s, 'something')
print s
在Cython中,如何更好地使用printf
函数?为什么它没有输出?
您可以使用wurlitzer
包来捕获C级别的标准输出和错误,然后将其重定向到IPython。
例如,在您的Jupyter笔记本中包含以下代码块:
%load_ext Cython
%load_ext wurlitzer
%%cython
from libc.stdio cimport printf
def test():
printf('abc')
test()
# prints "abc"
fcntl
。 - eadsource.c
中与printf()
一起使用,也无法在%%cython
单元格中的cdef extern from "source.c"
中使用。有什么想法吗? - Jayen输出将会在运行Jupyter notebook的终端(控制台)中打印。不确定如何在Jupyter中显示它。