{"id":1187067,"date":"2025-01-15T20:00:41","date_gmt":"2025-01-15T12:00:41","guid":{"rendered":""},"modified":"2025-01-15T20:00:45","modified_gmt":"2025-01-15T12:00:45","slug":"python%e5%a6%82%e4%bd%95%e5%ae%9a%e4%b9%89%e8%87%aa%e5%b7%b1%e7%9a%84%e5%ad%97%e5%ba%93","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1187067.html","title":{"rendered":"python\u5982\u4f55\u5b9a\u4e49\u81ea\u5df1\u7684\u5b57\u5e93"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25135713\/b41d2fee-2f88-4f63-b5f3-04ffb9341056.webp\" alt=\"python\u5982\u4f55\u5b9a\u4e49\u81ea\u5df1\u7684\u5b57\u5e93\" \/><\/p>\n<p><p> \u5b9a\u4e49\u81ea\u5df1\u7684\u5b57\u5e93\u662fPython\u4e2d\u4e00\u4e2a\u6709\u8da3\u4e14\u5b9e\u7528\u7684\u4efb\u52a1\uff0c<strong>\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u81ea\u5df1\u7684\u5b57\u4f53\u6587\u4ef6\u3001\u4f7f\u7528Bitmap\u5b57\u4f53\u3001\u5229\u7528PIL\u5e93\u7ed8\u5236\u5b57\u4f53\u56fe\u50cf<\/strong>\u7b49\u65b9\u6cd5\u6765\u5b9e\u73b0\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PIL\u5e93\u7ed8\u5236\u5b57\u4f53\u56fe\u50cf\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u521b\u5efa\u81ea\u5df1\u7684\u5b57\u4f53\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u521b\u5efa\u81ea\u5df1\u7684\u5b57\u4f53\u6587\u4ef6\u662f\u5b9a\u4e49\u5b57\u5e93\u7684\u4e00\u79cd\u57fa\u7840\u65b9\u6cd5\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u5b57\u4f53\u8bbe\u8ba1\u8f6f\u4ef6\uff08\u5982FontForge\uff09\u521b\u5efa\u4e00\u4e2a\u81ea\u5b9a\u4e49\u5b57\u4f53\uff0c\u7136\u540e\u5c06\u5176\u4fdd\u5b58\u4e3a\u5e38\u7528\u7684\u5b57\u4f53\u683c\u5f0f\uff08\u5982TTF\u6216OTF\uff09\u3002\u63a5\u4e0b\u6765\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>Pillow<\/code>\u5e93\u6765\u52a0\u8f7d\u548c\u4f7f\u7528\u8be5\u5b57\u4f53\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528FontForge\u521b\u5efa\u5b57\u4f53<\/h4>\n<\/p>\n<p><p>FontForge\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5b57\u4f53\u7f16\u8f91\u5668\uff0c\u53ef\u4ee5\u521b\u5efa\u548c\u7f16\u8f91TTF\u3001OTF\u7b49\u5b57\u4f53\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u7b80\u5355\u7684\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u4e0b\u8f7d\u5e76\u5b89\u88c5FontForge\u3002<\/li>\n<li>\u6253\u5f00FontForge\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5b57\u4f53\u9879\u76ee\u3002<\/li>\n<li>\u4e3a\u6bcf\u4e2a\u5b57\u7b26\u8bbe\u8ba1\u5b57\u5f62\u3002<\/li>\n<li>\u4fdd\u5b58\u5b57\u4f53\u9879\u76ee\u4e3aTTF\u6216OTF\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<p><h4>2. \u4f7f\u7528Pillow\u52a0\u8f7d\u548c\u4f7f\u7528\u5b57\u4f53<\/h4>\n<\/p>\n<p><p>Pillow\u662fPython Imaging Library\u7684\u4e00\u4e2a\u5206\u652f\uff0c\u63d0\u4f9b\u4e86\u5bf9\u56fe\u50cf\u5904\u7406\u7684\u652f\u6301\u3002\u53ef\u4ee5\u4f7f\u7528Pillow\u52a0\u8f7d\u81ea\u5b9a\u4e49\u5b57\u4f53\u5e76\u5728\u56fe\u50cf\u4e0a\u7ed8\u5236\u6587\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw, ImageFont<\/p>\n<h2><strong>\u52a0\u8f7d\u81ea\u5b9a\u4e49\u5b57\u4f53<\/strong><\/h2>\n<p>font_path = &quot;path\/to\/your\/custom_font.ttf&quot;<\/p>\n<p>font = ImageFont.truetype(font_path, size=40)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.new(&quot;RGB&quot;, (400, 200), color=&quot;white&quot;)<\/p>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u7ed8\u5236\u6587\u672c<\/strong><\/h2>\n<p>text = &quot;Hello, world!&quot;<\/p>\n<p>draw.text((10, 10), text, font=font, fill=&quot;black&quot;)<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&quot;output_image.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528Bitmap\u5b57\u4f53<\/h3>\n<\/p>\n<p><p>Bitmap\u5b57\u4f53\u662f\u4e00\u79cd\u901a\u8fc7\u4f4d\u56fe\u8868\u793a\u5b57\u7b26\u7684\u5b57\u4f53\uff0c\u53ef\u4ee5\u901a\u8fc7Python\u751f\u6210\u548c\u4f7f\u7528\u81ea\u5b9a\u4e49\u7684Bitmap\u5b57\u4f53\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efaBitmap\u5b57\u4f53<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u624b\u52a8\u521b\u5efaBitmap\u5b57\u4f53\uff0c\u6216\u8005\u4f7f\u7528\u73b0\u6709\u7684\u5de5\u5177\u751f\u6210Bitmap\u5b57\u4f53\u3002\u6bcf\u4e2a\u5b57\u7b26\u7528\u4e00\u4e2a\u4f4d\u56fe\u8868\u793a\uff0c\u4f4d\u56fe\u4e2d\u7684\u50cf\u7d20\u8868\u793a\u5b57\u7b26\u7684\u5f62\u72b6\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Bitmap\u5b57\u4f53<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u52a0\u8f7d\u548c\u4f7f\u7528Bitmap\u5b57\u4f53\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u52a0\u8f7dBitmap\u5b57\u4f53\u56fe\u50cf<\/strong><\/h2>\n<p>bitmap_font_image = Image.open(&quot;path\/to\/bitmap_font.png&quot;)<\/p>\n<h2><strong>\u5b9a\u4e49\u5b57\u7b26\u7684\u4f4d\u56fe\u7d22\u5f15<\/strong><\/h2>\n<p>character_map = {<\/p>\n<p>    &#39;A&#39;: (0, 0, 8, 8),<\/p>\n<p>    &#39;B&#39;: (8, 0, 16, 8),<\/p>\n<p>    # \u6dfb\u52a0\u5176\u4ed6\u5b57\u7b26\u6620\u5c04<\/p>\n<p>}<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.new(&quot;RGB&quot;, (400, 200), color=&quot;white&quot;)<\/p>\n<h2><strong>\u7ed8\u5236\u6587\u672c<\/strong><\/h2>\n<p>text = &quot;AB&quot;<\/p>\n<p>x, y = 10, 10<\/p>\n<p>for char in text:<\/p>\n<p>    if char in character_map:<\/p>\n<p>        bbox = character_map[char]<\/p>\n<p>        char_image = bitmap_font_image.crop(bbox)<\/p>\n<p>        image.paste(char_image, (x, y))<\/p>\n<p>        x += char_image.width<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&quot;output_image.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5229\u7528PIL\u5e93\u7ed8\u5236\u5b57\u4f53\u56fe\u50cf<\/h3>\n<\/p>\n<p><p>PIL\u5e93\u4e0d\u4ec5\u53ef\u4ee5\u52a0\u8f7d\u5b57\u4f53\uff0c\u8fd8\u53ef\u4ee5\u624b\u52a8\u7ed8\u5236\u5b57\u4f53\u56fe\u50cf\uff0c\u4ece\u800c\u5b9e\u73b0\u81ea\u5b9a\u4e49\u5b57\u4f53\u663e\u793a\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa\u5b57\u4f53\u56fe\u50cf<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Pillow\u5e93\u624b\u52a8\u7ed8\u5236\u6bcf\u4e2a\u5b57\u7b26\u7684\u56fe\u50cf\uff0c\u5e76\u4fdd\u5b58\u4e3a\u5355\u72ec\u7684\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5b57\u7b26\u56fe\u50cf<\/strong><\/h2>\n<p>char_image = Image.new(&quot;RGB&quot;, (8, 8), color=&quot;white&quot;)<\/p>\n<p>draw = ImageDraw.Draw(char_image)<\/p>\n<p>draw.rectangle([2, 2, 6, 6], fill=&quot;black&quot;)<\/p>\n<h2><strong>\u4fdd\u5b58\u5b57\u7b26\u56fe\u50cf<\/strong><\/h2>\n<p>char_image.save(&quot;char_A.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u5b57\u4f53\u56fe\u50cf<\/h4>\n<\/p>\n<p><p>\u52a0\u8f7d\u548c\u4f7f\u7528\u8fd9\u4e9b\u5b57\u7b26\u56fe\u50cf\uff0c\u5b9e\u73b0\u81ea\u5b9a\u4e49\u5b57\u4f53\u663e\u793a\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image<\/p>\n<h2><strong>\u52a0\u8f7d\u5b57\u7b26\u56fe\u50cf<\/strong><\/h2>\n<p>char_A_image = Image.open(&quot;char_A.png&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.new(&quot;RGB&quot;, (400, 200), color=&quot;white&quot;)<\/p>\n<h2><strong>\u7ed8\u5236\u6587\u672c<\/strong><\/h2>\n<p>text = &quot;AA&quot;<\/p>\n<p>x, y = 10, 10<\/p>\n<p>for char in text:<\/p>\n<p>    if char == &#39;A&#39;:<\/p>\n<p>        image.paste(char_A_image, (x, y))<\/p>\n<p>        x += char_A_image.width<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&quot;output_image.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u7efc\u5408\u8fd0\u7528\u81ea\u5b9a\u4e49\u5b57\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u7efc\u5408\u8fd0\u7528\u591a\u79cd\u65b9\u6cd5\u6765\u5b9a\u4e49\u548c\u4f7f\u7528\u81ea\u5b9a\u4e49\u5b57\u5e93\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7efc\u5408\u5b9e\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u81ea\u5b9a\u4e49\u5b57\u4f53\u6587\u4ef6\u548cBitmap\u5b57\u4f53\u7ed3\u5408\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from PIL import Image, ImageDraw, ImageFont<\/p>\n<h2><strong>\u52a0\u8f7d\u81ea\u5b9a\u4e49\u5b57\u4f53\u6587\u4ef6<\/strong><\/h2>\n<p>font_path = &quot;path\/to\/your\/custom_font.ttf&quot;<\/p>\n<p>font = ImageFont.truetype(font_path, size=40)<\/p>\n<h2><strong>\u52a0\u8f7dBitmap\u5b57\u4f53\u56fe\u50cf<\/strong><\/h2>\n<p>bitmap_font_image = Image.open(&quot;path\/to\/bitmap_font.png&quot;)<\/p>\n<h2><strong>\u5b9a\u4e49\u5b57\u7b26\u7684\u4f4d\u56fe\u7d22\u5f15<\/strong><\/h2>\n<p>character_map = {<\/p>\n<p>    &#39;A&#39;: (0, 0, 8, 8),<\/p>\n<p>    &#39;B&#39;: (8, 0, 16, 8),<\/p>\n<p>    # \u6dfb\u52a0\u5176\u4ed6\u5b57\u7b26\u6620\u5c04<\/p>\n<p>}<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u7a7a\u767d\u56fe\u50cf<\/strong><\/h2>\n<p>image = Image.new(&quot;RGB&quot;, (800, 400), color=&quot;white&quot;)<\/p>\n<p>draw = ImageDraw.Draw(image)<\/p>\n<h2><strong>\u7ed8\u5236\u6587\u672c\uff08\u4f7f\u7528\u81ea\u5b9a\u4e49\u5b57\u4f53\u6587\u4ef6\uff09<\/strong><\/h2>\n<p>text = &quot;Hello, world!&quot;<\/p>\n<p>draw.text((10, 10), text, font=font, fill=&quot;black&quot;)<\/p>\n<h2><strong>\u7ed8\u5236\u6587\u672c\uff08\u4f7f\u7528Bitmap\u5b57\u4f53\uff09<\/strong><\/h2>\n<p>bitmap_text = &quot;AB&quot;<\/p>\n<p>x, y = 10, 60<\/p>\n<p>for char in bitmap_text:<\/p>\n<p>    if char in character_map:<\/p>\n<p>        bbox = character_map[char]<\/p>\n<p>        char_image = bitmap_font_image.crop(bbox)<\/p>\n<p>        image.paste(char_image, (x, y))<\/p>\n<p>        x += char_image.width<\/p>\n<h2><strong>\u4fdd\u5b58\u56fe\u50cf<\/strong><\/h2>\n<p>image.save(&quot;combined_output_image.png&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u603b\u7ed3\u4e0e\u5efa\u8bae<\/h3>\n<\/p>\n<p><p>\u5b9a\u4e49\u548c\u4f7f\u7528\u81ea\u5b9a\u4e49\u5b57\u5e93\u5728Python\u4e2d\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u4e14\u7075\u6d3b\u7684\u6280\u80fd\u3002\u901a\u8fc7\u521b\u5efa\u81ea\u5df1\u7684\u5b57\u4f53\u6587\u4ef6\u3001\u4f7f\u7528Bitmap\u5b57\u4f53\u548cPIL\u5e93\u7ed8\u5236\u5b57\u4f53\u56fe\u50cf\uff0c\u53ef\u4ee5\u5b9e\u73b0\u591a\u79cd\u590d\u6742\u7684\u5b57\u4f53\u663e\u793a\u6548\u679c\u3002<\/p>\n<\/p>\n<p><p><strong>\u91cd\u8981\u7684\u6b65\u9aa4\u5305\u62ec\uff1a<\/strong><\/p>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efa\u81ea\u5df1\u7684\u5b57\u4f53\u6587\u4ef6<\/strong>\uff1a\u4f7f\u7528FontForge\u7b49\u5b57\u4f53\u8bbe\u8ba1\u8f6f\u4ef6\u521b\u5efaTTF\u6216OTF\u6587\u4ef6\u3002<\/li>\n<li><strong>\u4f7f\u7528Bitmap\u5b57\u4f53<\/strong>\uff1a\u624b\u52a8\u521b\u5efa\u6216\u4f7f\u7528\u5de5\u5177\u751f\u6210\u5b57\u7b26\u7684\u4f4d\u56fe\uff0c\u5e76\u5728\u56fe\u50cf\u4e0a\u7ed8\u5236\u8fd9\u4e9b\u5b57\u7b26\u3002<\/li>\n<li><strong>\u5229\u7528PIL\u5e93\u7ed8\u5236\u5b57\u4f53\u56fe\u50cf<\/strong>\uff1a\u624b\u52a8\u7ed8\u5236\u5b57\u7b26\u56fe\u50cf\uff0c\u5b9e\u73b0\u81ea\u5b9a\u4e49\u5b57\u4f53\u663e\u793a\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u7efc\u5408\u8fd0\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5728Python\u4e2d\u5b9e\u73b0\u9ad8\u5ea6\u81ea\u5b9a\u4e49\u7684\u5b57\u4f53\u6548\u679c\uff0c\u6ee1\u8db3\u5404\u79cd\u5e94\u7528\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><h4>\u5efa\u8bae<\/h4>\n<\/p>\n<ul>\n<li><strong>\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177<\/strong>\uff1a\u6839\u636e\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5b57\u4f53\u8bbe\u8ba1\u5de5\u5177\u548c\u5e93\uff0c\u786e\u4fdd\u5b9e\u73b0\u6700\u4f18\u7684\u5b57\u4f53\u6548\u679c\u3002<\/li>\n<li><strong>\u4f18\u5316\u5b57\u7b26\u6620\u5c04<\/strong>\uff1a\u5728\u4f7f\u7528Bitmap\u5b57\u4f53\u65f6\uff0c\u4f18\u5316\u5b57\u7b26\u6620\u5c04\u4ee5\u63d0\u9ad8\u7ed8\u5236\u6548\u7387\u3002<\/li>\n<li><strong>\u6d4b\u8bd5\u548c\u8c03\u6574<\/strong>\uff1a\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\u4e0d\u65ad\u6d4b\u8bd5\u548c\u8c03\u6574\u5b57\u4f53\u6548\u679c\uff0c\u786e\u4fdd\u5b57\u7b26\u663e\u793a\u7684\u51c6\u786e\u6027\u548c\u7f8e\u89c2\u6027\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4e0d\u65ad\u63a2\u7d22\u548c\u5b9e\u8df5\uff0c\u76f8\u4fe1\u4f60\u80fd\u591f\u5728Python\u4e2d\u5b9a\u4e49\u548c\u4f7f\u7528\u51fa\u8272\u7684\u81ea\u5b9a\u4e49\u5b57\u5e93\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u548c\u4f7f\u7528\u81ea\u5b9a\u4e49\u5b57\u5e93\uff1f<\/strong><br \/>\u5728Python\u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u5b57\u5e93\u901a\u5e38\u6d89\u53ca\u4f7f\u7528\u5b57\u5178\u6216\u96c6\u5408\u6765\u5b58\u50a8\u5b57\u7b26\u548c\u5176\u5bf9\u5e94\u7684\u542b\u4e49\u6216\u7528\u9014\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b57\u5178\u6765\u5c06\u7279\u5b9a\u7684\u5b57\u7b26\u6620\u5c04\u5230\u5176\u5b9a\u4e49\u6216\u529f\u80fd\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a  <\/p>\n<pre><code class=\"language-python\">custom_dict = {\n    &#39;A&#39;: &#39;Apple&#39;,\n    &#39;B&#39;: &#39;Banana&#39;,\n    &#39;C&#39;: &#39;Cherry&#39;\n}\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5b57\u5178<code>custom_dict<\/code>\u5c31\u53ef\u4ee5\u88ab\u89c6\u4e3a\u4e00\u4e2a\u5b57\u5e93\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u952e\u6765\u8bbf\u95ee\u76f8\u5e94\u7684\u503c\u3002<\/p>\n<p><strong>\u81ea\u5b9a\u4e49\u5b57\u5e93\u7684\u4f7f\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u81ea\u5b9a\u4e49\u5b57\u5e93\u5728\u8bb8\u591a\u573a\u666f\u4e2d\u975e\u5e38\u6709\u7528\uff0c\u6bd4\u5982\u6587\u672c\u5206\u6790\u3001\u81ea\u7136\u8bed\u8a00\u5904\u7406\u3001\u6e38\u620f\u5f00\u53d1\u7b49\u3002\u5728\u6587\u672c\u5206\u6790\u4e2d\uff0c\u53ef\u4ee5\u5229\u7528\u81ea\u5b9a\u4e49\u5b57\u5e93\u6765\u8bc6\u522b\u7279\u5b9a\u7684\u8bcd\u6c47\u6216\u672f\u8bed\u3002\u5728\u6e38\u620f\u5f00\u53d1\u4e2d\uff0c\u5b57\u5e93\u53ef\u4ee5\u5e2e\u52a9\u5b9a\u4e49\u89d2\u8272\u3001\u7269\u54c1\u6216\u573a\u666f\u7684\u540d\u79f0\u548c\u63cf\u8ff0\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u6301\u4e45\u5316\u81ea\u5b9a\u4e49\u5b57\u5e93\u6570\u636e\uff1f<\/strong><br \/>\u4e3a\u4e86\u5c06\u81ea\u5b9a\u4e49\u5b57\u5e93\u6570\u636e\u6301\u4e45\u5316\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e0d\u540c\u7684\u6587\u4ef6\u683c\u5f0f\uff0c\u5982JSON\u3001CSV\u6216\u6570\u636e\u5e93\u3002\u4f7f\u7528JSON\u683c\u5f0f\u7684\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import json\n\ncustom_dict = {\n    &#39;A&#39;: &#39;Apple&#39;,\n    &#39;B&#39;: &#39;Banana&#39;,\n    &#39;C&#39;: &#39;Cherry&#39;\n}\n\nwith open(&#39;custom_dict.json&#39;, &#39;w&#39;) as f:\n    json.dump(custom_dict, f)\n<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u53ef\u4ee5\u5c06\u5b57\u5e93\u6570\u636e\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4fbf\u5728\u540e\u7eed\u7684\u7a0b\u5e8f\u4e2d\u8bfb\u53d6\u548c\u4f7f\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5b9a\u4e49\u81ea\u5df1\u7684\u5b57\u5e93\u662fPython\u4e2d\u4e00\u4e2a\u6709\u8da3\u4e14\u5b9e\u7528\u7684\u4efb\u52a1\uff0c\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u81ea\u5df1\u7684\u5b57\u4f53\u6587\u4ef6\u3001\u4f7f\u7528Bitmap\u5b57\u4f53\u3001\u5229\u7528PI [&hellip;]","protected":false},"author":3,"featured_media":1187076,"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\/1187067"}],"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=1187067"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1187067\/revisions"}],"predecessor-version":[{"id":1187079,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1187067\/revisions\/1187079"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1187076"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1187067"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1187067"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1187067"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}