跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • jupyter 中通过 ctypes 调用 printf()时,不显示 printf()打印内容
未分類
20 12 月 2020

jupyter 中通过 ctypes 调用 printf()时,不显示 printf()打印内容

jupyter 中通过 ctypes 调用 printf()时,不显示 printf()打印内容

資深大佬 : XIVN1987 5

代码:

from ctypes import *  libc = cdll.LoadLibrary('msvcrt.dll') libc.printf(c_char_p(b'Hello %d %.2fn'), c_int(16), c_double(2.3)) 

在标准交互环境中显示内容为:

Hello 16 2.30 14 

在 ipython 中,显示内容为:

Hello 16 2.30 Out[31]: 14 

在 jupyter 中,显示内容为:

Out[15]: 14 

请问在 jupyter 中如何显示“Hello 16 2.30”

大佬有話說 (2)

  • 主 資深大佬 : XIVN1987

    找到一篇文章,上面说出现这种问题的原因是:
    IPython forwards the Python-level sys.stdout and sys.stderr, but it leaves the process-level file descriptors that C code will write to untouched. That means that in a context like this notebook, these functions will print to the terminal, because they are not captured.

    文章链接: https://notebook.community/minrk/wurlitzer/Demo

  • 主 資深大佬 : XIVN1987

    虽然在 jupyter notebook 中没有显示“Hello 16 2.30”,但在 jupyter.exe 终端中有显示,,能够验证代码的执行效果,,所以这个问题不算很严重

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具