{"id":246902,"date":"2020-12-20T21:25:07","date_gmt":"2020-12-20T13:25:07","guid":{"rendered":"http:\/\/4563.org\/?p=246902"},"modified":"2020-12-20T21:25:07","modified_gmt":"2020-12-20T13:25:07","slug":"jupyter-%e4%b8%ad%e9%80%9a%e8%bf%87-ctypes-%e8%b0%83%e7%94%a8-printf%e6%97%b6%ef%bc%8c%e4%b8%8d%e6%98%be%e7%a4%ba-printf%e6%89%93%e5%8d%b0%e5%86%85%e5%ae%b9","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=246902","title":{"rendered":"jupyter \u4e2d\u901a\u8fc7 ctypes \u8c03\u7528 printf()\u65f6\uff0c\u4e0d\u663e\u793a printf()\u6253\u5370\u5185\u5bb9"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  jupyter \u4e2d\u901a\u8fc7 ctypes \u8c03\u7528 printf()\u65f6\uff0c\u4e0d\u663e\u793a printf()\u6253\u5370\u5185\u5bb9               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : XIVN1987 <\/span>  <span><i><\/i> 5<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4ee3\u7801\uff1a<\/p>\n<pre><code>from ctypes import *  libc = cdll.LoadLibrary('msvcrt.dll') libc.printf(c_char_p(b'Hello %d %.2fn'), c_int(16), c_double(2.3)) <\/code><\/pre>\n<p>\u5728\u6807\u51c6\u4ea4\u4e92\u73af\u5883\u4e2d\u663e\u793a\u5185\u5bb9\u4e3a\uff1a<\/p>\n<pre><code>Hello 16 2.30 14 <\/code><\/pre>\n<p>\u5728 ipython \u4e2d\uff0c\u663e\u793a\u5185\u5bb9\u4e3a\uff1a<\/p>\n<pre><code>Hello 16 2.30 Out[31]: 14 <\/code><\/pre>\n<p>\u5728 jupyter \u4e2d\uff0c\u663e\u793a\u5185\u5bb9\u4e3a\uff1a<\/p>\n<pre><code>Out[15]: 14 <\/code><\/pre>\n<p>\u8bf7\u95ee\u5728 jupyter \u4e2d\u5982\u4f55\u663e\u793a\u201cHello 16 2.30\u201d<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>2<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"4803346\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : XIVN1987 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u627e\u5230\u4e00\u7bc7\u6587\u7ae0\uff0c\u4e0a\u9762\u8bf4\u51fa\u73b0\u8fd9\u79cd\u95ee\u9898\u7684\u539f\u56e0\u662f\uff1a<br \/>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.<\/p>\n<p>\u6587\u7ae0\u94fe\u63a5\uff1a https:\/\/notebook.community\/minrk\/wurlitzer\/Demo                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4803347\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : XIVN1987 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u867d\u7136\u5728 jupyter notebook \u4e2d\u6ca1\u6709\u663e\u793a\u201cHello 16 2.30\u201d\uff0c\u4f46\u5728 jupyter.exe \u7ec8\u7aef\u4e2d\u6709\u663e\u793a\uff0c\uff0c\u80fd\u591f\u9a8c\u8bc1\u4ee3\u7801\u7684\u6267\u884c\u6548\u679c\uff0c\uff0c\u6240\u4ee5\u8fd9\u4e2a\u95ee\u9898\u4e0d\u7b97\u5f88\u4e25\u91cd                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>jupyter \u4e2d\u901a\u8fc7 ctype&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/246902"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=246902"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/246902\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=246902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=246902"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=246902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}