{"id":204531,"date":"2025-05-29T14:19:33","date_gmt":"2025-05-29T06:19:33","guid":{"rendered":"https:\/\/server.hk\/cnblog\/204531\/"},"modified":"2025-05-29T14:19:33","modified_gmt":"2025-05-29T06:19:33","slug":"python3-%e6%89%a7%e8%a1%8c%e8%84%9a%e6%9c%ac%e6%97%b6%e9%81%ad%e9%81%87typeerror-not-all-arguments-converted-during-string-formatting%e9%97%ae%e9%a2%98%ef%bc%9a%e5%a6%82%e4%bd%95","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/204531\/","title":{"rendered":"Python3 \u6267\u884c\u811a\u672c\u65f6\u906d\u9047\u201cTypeError: not all arguments converted during string formatting\u201d\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Python3 \u6267\u884c\u811a\u672c\u65f6\u906d\u9047\u201cTypeError: not all arguments converted during string formatting\u201d\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3\uff1f<\/h1>\n<p>\u4e0d\u77e5\u9053\u5927\u5bb6\u662f\u5426\u719f\u6089\uff1f\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPython3 \u6267\u884c\u811a\u672c\u65f6\u906d\u9047\u201cTypeError: not all arguments converted during string formatting\u201d\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u5728\u770b\u5b8c\u672c\u7bc7\u6587\u7ae0\u540e\uff0c\u6709\u66f4\u597d\u7684\u5efa\u8bae\u6216\u8005\u53d1\u73b0\u54ea\u91cc\u6709\u95ee\u9898\uff0c\u5e0c\u671b\u5927\u5bb6\u90fd\u80fd\u79ef\u6781\u8bc4\u8bba\u6307\u51fa\uff0c\u8c22\u8c22\uff01\u5e0c\u671b\u6211\u4eec\u80fd\u4e00\u8d77\u52a0\u6cb9\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241110\/1731198089672ffc8918b8f.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>python3\u6267\u884c\u811a\u672c\u65f6\u906d\u9047\u201ctypeerror: not all arguments converted during string formatting\u201d<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5728\u6267\u884cpython\u811a\u672c\u65f6\uff0c\u9047\u5230\u4e86\u4ee5\u4e0b\u9519\u8bef\uff1a<\/p>\n<pre>typeerror: not all arguments converted during string formatting<\/pre>\n<p>\u540c\u65f6\uff0c\u4ee3\u7801\u4e2d\u90e8\u5206\u6d89\u53ca\u7684\u64cd\u4f5c\u4e3a\uff1a<\/p>\n<pre>cursor.execute(tgt_sql)\nrows = cursor.fetchall()\nout_tgt.write('%s\\n' % rows)<\/pre>\n<p><strong>\u5206\u6790\uff1a<\/strong><\/p>\n<p>\u9519\u8bef\u63d0\u793a\u8868\u660e\uff0c\u5728\u8fdb\u884c\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65f6\uff0c\u5e76\u975e\u6240\u6709\u53c2\u6570\u90fd\u7ecf\u8fc7\u8f6c\u6362\u3002\u8fd9\u662f\u56e0\u4e3a\u5728\u4f7f\u7528%\u64cd\u4f5c\u7b26\u8fdb\u884c\u5b57\u7b26\u4e32\u683c\u5f0f\u5316\u65f6\uff0c\u5bf9\u4e8e\u4e0d\u540c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u9700\u8981\u4f7f\u7528\u76f8\u5e94\u7684\u683c\u5f0f\u7b26\u53f7\u3002\u5728\u8be5\u60c5\u51b5\u4e0b\uff0c\u5e94\u5c06rows\u53d8\u91cf\u89c6\u4e3a\u5143\u7ec4\u6216\u6570\u7ec4\uff0c\u9700\u8981\u4f7f\u7528%s\u683c\u5f0f\u7b26\u53f7\u8fdb\u884c\u8f6c\u6362\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u5c06\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>out_tgt.write('%s\\n' % rows)<\/pre>\n<p>\u6539\u4e3a\uff1a<\/p>\n<pre>out_tgt.write('%s\\n' % (rows,))<\/pre>\n<p>\u901a\u8fc7\u6dfb\u52a0\u62ec\u53f7\uff0c\u5c06rows\u53d8\u91cf\u5f3a\u5236\u8f6c\u6362\u4e3a\u5143\u7ec4\uff0c\u4ece\u800c\u89e3\u51b3\u4e86\u683c\u5f0f\u5316\u95ee\u9898\u3002<\/p>\n<p><strong>\u793a\u4f8b\u4ee3\u7801\uff1a<\/strong><\/p>\n<p>\u4fee\u6539\u540e\u7684\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre>cursor.execute(tgt_sql)\nrows = cursor.fetchall()\nout_tgt.write('%s\\n' % (rows,))<\/pre>\n<p>\u4fee\u6539\u540e\uff0c\u811a\u672c\u5c06\u6b63\u5e38\u6267\u884c\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aPython3 \u6267\u884c\u811a\u672c\u65f6\u906d\u9047\u201cTypeError: not all arguments converted during string formatting\u201d\u95ee\u9898\uff1a\u5982\u4f55\u89e3\u51b3\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python3 \u6267\u884c\u811a\u672c\u65f6\u906d\u9047\u201c&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-204531","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=204531"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/204531\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=204531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=204531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=204531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}