{"id":1175547,"date":"2025-01-15T17:33:28","date_gmt":"2025-01-15T09:33:28","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1175547.html"},"modified":"2025-01-15T17:33:32","modified_gmt":"2025-01-15T09:33:32","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8python%e4%b8%ad%e8%be%93%e5%85%a5%e4%b8%ad%e6%96%87","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1175547.html","title":{"rendered":"\u5982\u4f55\u5728python\u4e2d\u8f93\u5165\u4e2d\u6587"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25110941\/139b641a-dce8-4b80-b829-35912ff9cfab.webp\" alt=\"\u5982\u4f55\u5728python\u4e2d\u8f93\u5165\u4e2d\u6587\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8f93\u5165\u4e2d\u6587\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528UTF-8\u7f16\u7801\u3001\u4f7f\u7528Unicode\u7f16\u7801\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u548c\u6a21\u5757\u3001\u8bbe\u7f6e\u6587\u4ef6\u7f16\u7801<\/strong>\u3002\u5176\u4e2d\uff0c\u6700\u5e38\u7528\u7684\u662f\u4f7f\u7528UTF-8\u7f16\u7801\uff0c\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528UTF-8\u7f16\u7801\uff1a<\/strong>Python\u9ed8\u8ba4\u4f7f\u7528UTF-8\u7f16\u7801\uff0c\u8fd9\u4f7f\u5f97\u5904\u7406\u4e2d\u6587\u53d8\u5f97\u975e\u5e38\u65b9\u4fbf\u3002\u53ea\u9700\u8981\u786e\u4fdd\u6e90\u4ee3\u7801\u6587\u4ef6\u662f\u4ee5UTF-8\u7f16\u7801\u4fdd\u5b58\u7684\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u8f93\u5165\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># -*- coding: utf-8 -*-<\/p>\n<p>print(&quot;\u4f60\u597d\uff0c\u4e16\u754c&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u4e0a\u9762\u7684\u4ee3\u7801\u4e2d\uff0c\u7b2c\u4e00\u884c\u662f\u4e00\u4e2a\u7f16\u7801\u58f0\u660e\uff0c\u8868\u793a\u8be5\u6587\u4ef6\u4f7f\u7528UTF-8\u7f16\u7801\u3002\u8fd9\u6837\uff0cPython\u5c31\u80fd\u591f\u6b63\u786e\u5730\u89e3\u91ca\u548c\u663e\u793a\u4e2d\u6587\u5b57\u7b26\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528UTF-8\u7f16\u7801<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u4f7f\u7528UTF-8\u7f16\u7801\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u975e\u5e38\u65b9\u4fbf\u3002\u53ea\u9700\u8981\u786e\u4fdd\u6e90\u4ee3\u7801\u6587\u4ef6\u662f\u4ee5UTF-8\u7f16\u7801\u4fdd\u5b58\u7684\uff0c\u5e76\u5728\u6587\u4ef6\u7684\u5f00\u5934\u52a0\u4e0a\u7f16\u7801\u58f0\u660e\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u5728\u4ee3\u7801\u4e2d\u8f93\u5165\u548c\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u7f16\u7801\u58f0\u660e<\/h4>\n<\/p>\n<p><p>\u5728Python\u6587\u4ef6\u7684\u5f00\u5934\u52a0\u4e0a\u7f16\u7801\u58f0\u660e\u662f\u4e00\u4e2a\u597d\u7684\u4e60\u60ef\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fddPython\u89e3\u91ca\u5668\u6b63\u786e\u5730\u5904\u7406\u6587\u4ef6\u4e2d\u7684\u4e2d\u6587\u5b57\u7b26\u3002\u7f16\u7801\u58f0\u660e\u7684\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># -*- coding: utf-8 -*-<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u793a\u4f8b\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u5c55\u793a\u4e86\u5982\u4f55\u5728Python\u4e2d\u4f7f\u7528UTF-8\u7f16\u7801\u8f93\u5165\u548c\u8f93\u51fa\u4e2d\u6587\u5b57\u7b26\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># -*- coding: utf-8 -*-<\/p>\n<p>def greet(name):<\/p>\n<p>    return f&quot;\u4f60\u597d\uff0c{name}\uff01&quot;<\/p>\n<p>print(greet(&quot;\u4e16\u754c&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u51fd\u6570 <code>greet<\/code>\uff0c\u5b83\u63a5\u53d7\u4e00\u4e2a\u540d\u5b57\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u4e00\u4e2a\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u95ee\u5019\u8bed\u3002\u7136\u540e\uff0c\u6211\u4eec\u8c03\u7528\u8fd9\u4e2a\u51fd\u6570\u5e76\u6253\u5370\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Unicode\u7f16\u7801<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528UTF-8\u7f16\u7801\u5916\uff0c\u8fd8\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528Unicode\u7f16\u7801\u8868\u793a\u4e2d\u6587\u5b57\u7b26\u3002Unicode\u7f16\u7801\u662f\u4e00\u79cd\u901a\u7528\u7684\u5b57\u7b26\u7f16\u7801\u6807\u51c6\uff0c\u53ef\u4ee5\u8868\u793a\u4e16\u754c\u4e0a\u51e0\u4e4e\u6240\u6709\u7684\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Unicode\u5b57\u7b26\u8868\u793a<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528Unicode\u8f6c\u4e49\u5e8f\u5217\u8868\u793a\u4e2d\u6587\u5b57\u7b26\u3002Unicode\u8f6c\u4e49\u5e8f\u5217\u7684\u683c\u5f0f\u662f <code>\\u<\/code> \u52a0\u4e0a\u56db\u4f4d\u5341\u516d\u8fdb\u5236\u6570\u5b57\u3002\u4f8b\u5982\uff0c\u4e2d\u6587\u5b57\u7b26 &quot;\u4f60&quot; \u7684Unicode\u7f16\u7801\u662f <code>\\u4f60<\/code>\uff0c\u5b57\u7b26 &quot;\u597d&quot; \u7684Unicode\u7f16\u7801\u662f <code>\\u597d<\/code>\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u793a\u4f8b\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Unicode\u7f16\u7801\u8868\u793a\u4e2d\u6587\u5b57\u7b26\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    return f&quot;\\u4f60\\u597d\\uff0c{name}\uff01&quot;<\/p>\n<p>print(greet(&quot;\\u4e16\\u754c&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528Unicode\u8f6c\u4e49\u5e8f\u5217\u8868\u793a\u4e2d\u6587\u5b57\u7b26 &quot;\u4f60&quot;\u3001&quot;\u597d&quot; \u548c &quot;\u4e16\u754c&quot;\u3002\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u5c06\u8f93\u51fa &quot;\u4f60\u597d\uff0c\u4e16\u754c\uff01&quot;\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u548c\u6a21\u5757<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u4e00\u4e9b\u5185\u7f6e\u51fd\u6570\u548c\u6a21\u5757\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>str.encode<\/code> \u548c <code>str.decode<\/code> \u65b9\u6cd5\u5bf9\u5b57\u7b26\u4e32\u8fdb\u884c\u7f16\u7801\u548c\u89e3\u7801\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b57\u7b26\u4e32\u7f16\u7801\u548c\u89e3\u7801<\/h4>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>str.encode<\/code> \u65b9\u6cd5\u5c06\u5b57\u7b26\u4e32\u7f16\u7801\u4e3a\u5b57\u8282\u5e8f\u5217\uff0c\u7136\u540e\u4f7f\u7528 <code>str.decode<\/code> \u65b9\u6cd5\u5c06\u5b57\u8282\u5e8f\u5217\u89e3\u7801\u4e3a\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># -*- coding: utf-8 -*-<\/p>\n<p>s = &quot;\u4f60\u597d\uff0c\u4e16\u754c&quot;<\/p>\n<p>encoded_s = s.encode(&quot;utf-8&quot;)<\/p>\n<p>decoded_s = encoded_s.decode(&quot;utf-8&quot;)<\/p>\n<p>print(decoded_s)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u5c06\u5b57\u7b26\u4e32 <code>s<\/code> \u7f16\u7801\u4e3aUTF-8\u5b57\u8282\u5e8f\u5217\uff0c\u7136\u540e\u5c06\u8fd9\u4e2a\u5b57\u8282\u5e8f\u5217\u89e3\u7801\u4e3a\u5b57\u7b26\u4e32 <code>decoded_s<\/code>\u3002\u6700\u7ec8\uff0c\u6253\u5370\u89e3\u7801\u540e\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528<code>sys<\/code>\u6a21\u5757<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>sys<\/code> \u6a21\u5757\u4e2d\u7684 <code>sys.stdout<\/code> \u548c <code>sys.stdin<\/code> \u6765\u5904\u7406\u8f93\u5165\u548c\u8f93\u51fa\u4e2d\u7684\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>import io<\/p>\n<p>sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding=&#39;utf-8&#39;)<\/p>\n<p>print(&quot;\u4f60\u597d\uff0c\u4e16\u754c&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u91cd\u65b0\u8bbe\u7f6e\u4e86\u6807\u51c6\u8f93\u51fa\u7684\u7f16\u7801\u4e3aUTF-8\uff0c\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u8f93\u51fa\u7684\u4e2d\u6587\u5b57\u7b26\u88ab\u6b63\u786e\u663e\u793a\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u8bbe\u7f6e\u6587\u4ef6\u7f16\u7801<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u8bbe\u7f6e\u6587\u4ef6\u7684\u7f16\u7801\uff0c\u4ee5\u4fbf\u6b63\u786e\u5730\u8bfb\u5199\u4e2d\u6587\u5b57\u7b26\u3002\u53ef\u4ee5\u4f7f\u7528 <code>open<\/code> \u51fd\u6570\u7684 <code>encoding<\/code> \u53c2\u6570\u6765\u8bbe\u7f6e\u6587\u4ef6\u7684\u7f16\u7801\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5199\u5165\u4e2d\u6587\u5b57\u7b26\u5230\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5c06\u4e2d\u6587\u5b57\u7b26\u5199\u5165\u6587\u4ef6\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># -*- coding: utf-8 -*-<\/p>\n<p>with open(&quot;output.txt&quot;, &quot;w&quot;, encoding=&quot;utf-8&quot;) as f:<\/p>\n<p>    f.write(&quot;\u4f60\u597d\uff0c\u4e16\u754c&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>open<\/code> \u51fd\u6570\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u6307\u5b9a\u7f16\u7801\u4e3aUTF-8\uff0c\u7136\u540e\u5c06\u4e2d\u6587\u5b57\u7b26\u4e32\u5199\u5165\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4ece\u6587\u4ef6\u8bfb\u53d6\u4e2d\u6587\u5b57\u7b26<\/h4>\n<\/p>\n<p><p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4ece\u6587\u4ef6\u8bfb\u53d6\u4e2d\u6587\u5b57\u7b26\u7684\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># -*- coding: utf-8 -*-<\/p>\n<p>with open(&quot;output.txt&quot;, &quot;r&quot;, encoding=&quot;utf-8&quot;) as f:<\/p>\n<p>    content = f.read()<\/p>\n<p>print(content)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>open<\/code> \u51fd\u6570\u6253\u5f00\u4e00\u4e2a\u6587\u4ef6\uff0c\u5e76\u6307\u5b9a\u7f16\u7801\u4e3aUTF-8\uff0c\u7136\u540e\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u5e76\u6253\u5370\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u65f6\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5e93\uff0c\u4f8b\u5982 <code>chardet<\/code> \u7528\u4e8e\u68c0\u6d4b\u6587\u4ef6\u7f16\u7801\uff0c<code>pandas<\/code> \u7528\u4e8e\u5904\u7406\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>chardet<\/code>\u5e93\u68c0\u6d4b\u6587\u4ef6\u7f16\u7801<\/h4>\n<\/p>\n<p><p><code>chardet<\/code> \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u5b57\u7b26\u7f16\u7801\u68c0\u6d4b\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u68c0\u6d4b\u6587\u4ef6\u7684\u7f16\u7801\u7c7b\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import chardet<\/p>\n<p>with open(&quot;unknown_encoding.txt&quot;, &quot;rb&quot;) as f:<\/p>\n<p>    raw_data = f.read()<\/p>\n<p>    result = chardet.detect(raw_data)<\/p>\n<p>    encoding = result[&#39;encoding&#39;]<\/p>\n<p>    print(f&quot;\u6587\u4ef6\u7f16\u7801: {encoding}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>chardet.detect<\/code> \u65b9\u6cd5\u68c0\u6d4b\u6587\u4ef6\u7684\u7f16\u7801\u7c7b\u578b\uff0c\u5e76\u6253\u5370\u68c0\u6d4b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528<code>pandas<\/code>\u5e93\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u6570\u636e<\/h4>\n<\/p>\n<p><p><code>pandas<\/code> \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u6570\u636e\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<p>data = {&#39;\u540d\u79f0&#39;: [&#39;\u5f20\u4e09&#39;, &#39;\u674e\u56db&#39;, &#39;\u738b\u4e94&#39;], &#39;\u5e74\u9f84&#39;: [23, 24, 25]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<p>df.to_csv(&quot;output.csv&quot;, index=False, encoding=&quot;utf-8&quot;)<\/p>\n<p>print(pd.read_csv(&quot;output.csv&quot;, encoding=&quot;utf-8&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u6570\u636e\u5e27\uff0c\u5e76\u5c06\u5176\u4fdd\u5b58\u4e3aCSV\u6587\u4ef6\u3002\u7136\u540e\uff0c\u6211\u4eec\u8bfb\u53d6\u8fd9\u4e2aCSV\u6587\u4ef6\u5e76\u6253\u5370\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u5904\u7406\u4e2d\u6587\u8def\u5f84\u548c\u6587\u4ef6\u540d<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u6587\u4ef6\u8def\u5f84\u548c\u6587\u4ef6\u540d\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u60c5\u51b5\u3002\u53ef\u4ee5\u4f7f\u7528 <code>os<\/code> \u6a21\u5757\u548c <code>pathlib<\/code> \u6a21\u5757\u6765\u5904\u7406\u8fd9\u4e9b\u8def\u5f84\u548c\u6587\u4ef6\u540d\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u5904\u7406\u4e2d\u6587\u8def\u5f84<\/h4>\n<\/p>\n<p><p><code>os<\/code> \u6a21\u5757\u63d0\u4f9b\u4e86\u4e00\u4e9b\u51fd\u6570\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5904\u7406\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u6587\u4ef6\u8def\u5f84\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>path = &quot;\u6d4b\u8bd5\u76ee\u5f55\/\u6587\u4ef6.txt&quot;<\/p>\n<p>if not os.path.exists(&quot;\u6d4b\u8bd5\u76ee\u5f55&quot;):<\/p>\n<p>    os.makedirs(&quot;\u6d4b\u8bd5\u76ee\u5f55&quot;)<\/p>\n<p>with open(path, &quot;w&quot;, encoding=&quot;utf-8&quot;) as f:<\/p>\n<p>    f.write(&quot;\u8fd9\u662f\u4e00\u4e2a\u6d4b\u8bd5\u6587\u4ef6&quot;)<\/p>\n<p>print(os.listdir(&quot;\u6d4b\u8bd5\u76ee\u5f55&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u76ee\u5f55\u548c\u6587\u4ef6\uff0c\u5e76\u5217\u51fa\u4e86\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u4f7f\u7528<code>pathlib<\/code>\u6a21\u5757\u5904\u7406\u4e2d\u6587\u8def\u5f84<\/h4>\n<\/p>\n<p><p><code>pathlib<\/code> \u6a21\u5757\u63d0\u4f9b\u4e86\u66f4\u52a0\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u6765\u5904\u7406\u6587\u4ef6\u8def\u5f84\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from pathlib import Path<\/p>\n<p>path = Path(&quot;\u6d4b\u8bd5\u76ee\u5f55&quot;) \/ &quot;\u6587\u4ef6.txt&quot;<\/p>\n<p>path.parent.mkdir(parents=True, exist_ok=True)<\/p>\n<p>path.write_text(&quot;\u8fd9\u662f\u4e00\u4e2a\u6d4b\u8bd5\u6587\u4ef6&quot;, encoding=&quot;utf-8&quot;)<\/p>\n<p>print(list(path.parent.iterdir()))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>pathlib.Path<\/code> \u7c7b\u521b\u5efa\u4e86\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u76ee\u5f55\u548c\u6587\u4ef6\uff0c\u5e76\u5217\u51fa\u4e86\u76ee\u5f55\u4e2d\u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5728GUI\u5e94\u7528\u4e2d\u4f7f\u7528\u4e2d\u6587<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1GUI\u5e94\u7528\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u5904\u7406\u7528\u6237\u754c\u9762\u4e2d\u7684\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u4f7f\u7528 <code>tkinter<\/code> \u5e93\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684GUI\u5e94\u7528\uff0c\u5e76\u5728\u754c\u9762\u4e2d\u663e\u793a\u4e2d\u6587\u5b57\u7b26\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>tkinter<\/code>\u5e93\u521b\u5efaGUI\u5e94\u7528<\/h4>\n<\/p>\n<p><p><code>tkinter<\/code> \u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u521b\u5efa\u8de8\u5e73\u53f0\u7684GUI\u5e94\u7528\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;\u4e2d\u6587\u754c\u9762&quot;)<\/p>\n<p>label = tk.Label(root, text=&quot;\u4f60\u597d\uff0c\u4e16\u754c&quot;)<\/p>\n<p>label.pack()<\/p>\n<p>root.m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u7b80\u5355\u7684GUI\u7a97\u53e3\uff0c\u5e76\u5728\u7a97\u53e3\u4e2d\u663e\u793a\u4e86\u4e00\u4e2a\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u6807\u7b7e\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5904\u7406\u7528\u6237\u8f93\u5165\u7684\u4e2d\u6587\u5b57\u7b26<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>tkinter<\/code> \u5e93\u7684\u8f93\u5165\u63a7\u4ef6\u6765\u5904\u7406\u7528\u6237\u8f93\u5165\u7684\u4e2d\u6587\u5b57\u7b26\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import tkinter as tk<\/p>\n<p>def show_message():<\/p>\n<p>    message = entry.get()<\/p>\n<p>    label.config(text=message)<\/p>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;\u4e2d\u6587\u8f93\u5165&quot;)<\/p>\n<p>entry = tk.Entry(root)<\/p>\n<p>entry.pack()<\/p>\n<p>button = tk.Button(root, text=&quot;\u663e\u793a\u6d88\u606f&quot;, command=show_message)<\/p>\n<p>button.pack()<\/p>\n<p>label = tk.Label(root)<\/p>\n<p>label.pack()<\/p>\n<p>root.mainloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u5305\u542b\u8f93\u5165\u6846\u548c\u6309\u94ae\u7684GUI\u7a97\u53e3\uff0c\u7528\u6237\u53ef\u4ee5\u5728\u8f93\u5165\u6846\u4e2d\u8f93\u5165\u4e2d\u6587\u5b57\u7b26\uff0c\u5e76\u70b9\u51fb\u6309\u94ae\u663e\u793a\u8f93\u5165\u7684\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u5904\u7406\u4e2d\u6587\u7f16\u7801\u9519\u8bef<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u7f16\u7801\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u5c1d\u8bd5\u5c06\u975eUTF-8\u7f16\u7801\u7684\u5b57\u7b26\u4e32\u89e3\u7801\u4e3aUTF-8\u65f6\uff0c\u53ef\u80fd\u4f1a\u5f15\u53d1 <code>UnicodeDecodeError<\/code>\u3002\u53ef\u4ee5\u4f7f\u7528\u5f02\u5e38\u5904\u7406\u6765\u6355\u83b7\u548c\u5904\u7406\u8fd9\u4e9b\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u6355\u83b7\u7f16\u7801\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>try<\/code> \u548c <code>except<\/code> \u8bed\u53e5\u6765\u6355\u83b7\u7f16\u7801\u9519\u8bef\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">s = b&#39;\\xe4\\xbd\\xa0\\xe5\\xa5\\xbd&#39;<\/p>\n<p>try:<\/p>\n<p>    decoded_s = s.decode(&quot;utf-8&quot;)<\/p>\n<p>    print(decoded_s)<\/p>\n<p>except UnicodeDecodeError as e:<\/p>\n<p>    print(f&quot;\u89e3\u7801\u9519\u8bef: {e}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c1d\u8bd5\u5c06\u5b57\u8282\u5e8f\u5217 <code>s<\/code> \u89e3\u7801\u4e3aUTF-8\u5b57\u7b26\u4e32\uff0c\u5e76\u6355\u83b7\u53ef\u80fd\u7684 <code>UnicodeDecodeError<\/code> \u5f02\u5e38\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5904\u7406\u7f16\u7801\u9519\u8bef<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u9519\u8bef\u5904\u7406\u7b56\u7565\u6765\u5904\u7406\u7f16\u7801\u9519\u8bef\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>errors<\/code> \u53c2\u6570\u6307\u5b9a\u9519\u8bef\u5904\u7406\u7b56\u7565\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">s = b&#39;\\xe4\\xbd\\xa0\\xe5\\xa5\\xbd&#39;<\/p>\n<p>decoded_s = s.decode(&quot;utf-8&quot;, errors=&quot;replace&quot;)<\/p>\n<p>print(decoded_s)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>errors=&quot;replace&quot;<\/code> \u53c2\u6570\u6307\u5b9a\u5728\u9047\u5230\u89e3\u7801\u9519\u8bef\u65f6\uff0c\u7528\u66ff\u6362\u5b57\u7b26 <code>\ufffd<\/code> \u6765\u4ee3\u66ff\u9519\u8bef\u7684\u5b57\u8282\u5e8f\u5217\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u5904\u7406\u4e2d\u6587\u6587\u672c\u6570\u636e<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5305\u542b\u4e2d\u6587\u5b57\u7b26\u7684\u6587\u672c\u6570\u636e\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u8fdb\u884c\u6587\u672c\u6e05\u7406\u3001\u5206\u8bcd\u3001\u8bcd\u9891\u7edf\u8ba1\u7b49\u64cd\u4f5c\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>jieba<\/code> \u5e93\u8fdb\u884c\u4e2d\u6587\u5206\u8bcd\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>jieba<\/code>\u5e93\u8fdb\u884c\u4e2d\u6587\u5206\u8bcd<\/h4>\n<\/p>\n<p><p><code>jieba<\/code> \u662f\u4e00\u4e2a\u6d41\u884c\u7684\u4e2d\u6587\u5206\u8bcd\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u4e2d\u6587\u6587\u672c\u5207\u5206\u4e3a\u8bcd\u8bed\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import jieba<\/p>\n<p>text = &quot;\u6211\u7231\u81ea\u7136\u8bed\u8a00\u5904\u7406&quot;<\/p>\n<p>words = jieba.lcut(text)<\/p>\n<p>print(words)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>jieba.lcut<\/code> \u65b9\u6cd5\u5c06\u4e2d\u6587\u6587\u672c\u5207\u5206\u4e3a\u8bcd\u8bed\uff0c\u5e76\u6253\u5370\u5206\u8bcd\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8fdb\u884c\u8bcd\u9891\u7edf\u8ba1<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>collections.Counter<\/code> \u7c7b\u8fdb\u884c\u8bcd\u9891\u7edf\u8ba1\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from collections import Counter<\/p>\n<p>text = &quot;\u6211\u7231\u81ea\u7136\u8bed\u8a00\u5904\u7406\uff0c\u81ea\u7136\u8bed\u8a00\u5904\u7406\u5f88\u6709\u8da3&quot;<\/p>\n<p>words = jieba.lcut(text)<\/p>\n<p>word_counts = Counter(words)<\/p>\n<p>print(word_counts)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>Counter<\/code> \u7c7b\u5bf9\u5206\u8bcd\u7ed3\u679c\u8fdb\u884c\u8bcd\u9891\u7edf\u8ba1\uff0c\u5e76\u6253\u5370\u7edf\u8ba1\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u5904\u7406\u591a\u8bed\u8a00\u6587\u672c<\/h3>\n<\/p>\n<p><p>\u5728\u5904\u7406\u5305\u542b\u591a\u79cd\u8bed\u8a00\u7684\u6587\u672c\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u8bc6\u522b\u548c\u5904\u7406\u4e0d\u540c\u8bed\u8a00\u7684\u5b57\u7b26\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>langdetect<\/code> \u5e93\u8fdb\u884c\u8bed\u8a00\u68c0\u6d4b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u4f7f\u7528<code>langdetect<\/code>\u5e93\u8fdb\u884c\u8bed\u8a00\u68c0\u6d4b<\/h4>\n<\/p>\n<p><p><code>langdetect<\/code> \u662f\u4e00\u4e2a\u8bed\u8a00\u68c0\u6d4b\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u68c0\u6d4b\u6587\u672c\u7684\u8bed\u8a00\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from langdetect import detect<\/p>\n<p>text = &quot;\u4f60\u597d\uff0c\u4e16\u754c&quot;<\/p>\n<p>language = detect(text)<\/p>\n<p>print(f&quot;\u68c0\u6d4b\u5230\u7684\u8bed\u8a00: {language}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528 <code>detect<\/code> \u65b9\u6cd5\u68c0\u6d4b\u6587\u672c\u7684\u8bed\u8a00\uff0c\u5e76\u6253\u5370\u68c0\u6d4b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u5904\u7406\u591a\u8bed\u8a00\u6587\u672c<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u7ed3\u5408\u8bed\u8a00\u68c0\u6d4b\u548c\u7f16\u7801\u5904\u7406\u6280\u672f\uff0c\u5904\u7406\u5305\u542b\u591a\u79cd\u8bed\u8a00\u7684\u6587\u672c\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from langdetect import detect<\/p>\n<p>texts = [&quot;\u4f60\u597d\uff0c\u4e16\u754c&quot;, &quot;Hello, world&quot;, &quot;Bonjour le monde&quot;]<\/p>\n<p>for text in texts:<\/p>\n<p>    language = detect(text)<\/p>\n<p>    print(f&quot;\u6587\u672c: {text} - \u8bed\u8a00: {language}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u68c0\u6d4b\u4e86\u4e00\u7ec4\u591a\u8bed\u8a00\u6587\u672c\u7684\u8bed\u8a00\uff0c\u5e76\u6253\u5370\u68c0\u6d4b\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u4e00\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\u8f93\u5165\u548c\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u6709\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528UTF-8\u7f16\u7801\u3001\u4f7f\u7528Unicode\u7f16\u7801\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u548c\u6a21\u5757\u3001\u8bbe\u7f6e\u6587\u4ef6\u7f16\u7801\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u3001\u5904\u7406\u4e2d\u6587\u8def\u5f84\u548c\u6587\u4ef6\u540d\u3001\u5728GUI\u5e94\u7528\u4e2d\u4f7f\u7528\u4e2d\u6587\u3001\u5904\u7406\u4e2d\u6587\u7f16\u7801\u9519\u8bef\u3001\u5904\u7406\u4e2d\u6587\u6587\u672c\u6570\u636e\u3001\u5904\u7406\u591a\u8bed\u8a00\u6587\u672c\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e86\u89e3\u548c\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u5728Python\u7f16\u7a0b\u4e2d\u9047\u5230\u7684\u4e2d\u6587\u5b57\u7b26\u5904\u7406\u95ee\u9898\uff0c\u63d0\u9ad8\u7a0b\u5e8f\u7684\u517c\u5bb9\u6027\u548c\u7528\u6237\u4f53\u9a8c\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u60a8\u5728Python\u4e2d\u5904\u7406\u4e2d\u6587\u5b57\u7b26\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bbe\u7f6e\u4e2d\u6587\u7f16\u7801\u4ee5\u652f\u6301\u4e2d\u6587\u8f93\u5165\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>utf-8<\/code>\u7f16\u7801\u6765\u652f\u6301\u4e2d\u6587\u8f93\u5165\u3002\u901a\u5e38\u60c5\u51b5\u4e0b\uff0c\u786e\u4fdd\u5728\u6587\u4ef6\u7684\u5f00\u5934\u6dfb\u52a0<code># -*- coding: utf-8 -*-<\/code>\uff0c\u8fd9\u6837Python\u89e3\u91ca\u5668\u5c31\u4f1a\u4ee5<code>utf-8<\/code>\u7f16\u7801\u6765\u5904\u7406\u8be5\u6587\u4ef6\u3002\u6b64\u5916\uff0c\u4f7f\u7528<code>print<\/code>\u51fd\u6570\u8f93\u51fa\u4e2d\u6587\u65f6\uff0c\u4e5f\u8981\u786e\u4fdd\u7ec8\u7aef\u6216IDE\u652f\u6301\u4e2d\u6587\u663e\u793a\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u4f7f\u7528\u4e2d\u6587\u65f6\uff0c\u5e38\u89c1\u7684\u9519\u8bef\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5e38\u89c1\u7684\u9519\u8bef\u5305\u62ec\u7f16\u7801\u4e0d\u5339\u914d\u548c\u5b57\u7b26\u65e0\u6cd5\u8bc6\u522b\u7684\u95ee\u9898\u3002\u901a\u5e38\uff0c\u5f53\u4f60\u5c1d\u8bd5\u5728\u4e0d\u540c\u7f16\u7801\u7684\u73af\u5883\u4e2d\u8fd0\u884c\u7a0b\u5e8f\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230<code>UnicodeDecodeError<\/code>\u6216<code>UnicodeEncodeError<\/code>\u3002\u786e\u4fdd\u6240\u6709\u76f8\u5173\u6587\u4ef6\u548c\u7ec8\u7aef\u90fd\u91c7\u7528\u76f8\u540c\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u80fd\u6709\u6548\u907f\u514d\u8fd9\u4e9b\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u8bfb\u53d6\u5305\u542b\u4e2d\u6587\u7684\u6587\u4ef6\uff1f<\/strong><br \/>\u5728\u8bfb\u53d6\u5305\u542b\u4e2d\u6587\u7684\u6587\u4ef6\u65f6\uff0c\u53ef\u4ee5\u5728\u6253\u5f00\u6587\u4ef6\u65f6\u6307\u5b9a\u7f16\u7801\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>open(&#39;file.txt&#39;, &#39;r&#39;, encoding=&#39;utf-8&#39;)<\/code>\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fddPython\u6b63\u786e\u5730\u8bfb\u53d6\u6587\u4ef6\u4e2d\u7684\u4e2d\u6587\u5b57\u7b26\uff0c\u907f\u514d\u56e0\u7f16\u7801\u4e0d\u4e00\u81f4\u5bfc\u81f4\u7684\u9519\u8bef\u3002\u4f7f\u7528<code>with<\/code>\u8bed\u53e5\u53ef\u4ee5\u66f4\u597d\u5730\u7ba1\u7406\u6587\u4ef6\u7684\u6253\u5f00\u548c\u5173\u95ed\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8f93\u5165\u4e2d\u6587\u6709\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528UTF-8\u7f16\u7801\u3001\u4f7f\u7528Unicode\u7f16\u7801\u3001\u4f7f\u7528\u5185\u7f6e\u51fd\u6570\u548c\u6a21\u5757\u3001\u8bbe\u7f6e\u6587 [&hellip;]","protected":false},"author":3,"featured_media":1175557,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1175547"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1175547"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1175547\/revisions"}],"predecessor-version":[{"id":1175559,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1175547\/revisions\/1175559"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1175557"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1175547"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1175547"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1175547"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}