{"id":1183595,"date":"2025-01-15T19:16:25","date_gmt":"2025-01-15T11:16:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1183595.html"},"modified":"2025-01-15T19:16:29","modified_gmt":"2025-01-15T11:16:29","slug":"python%e5%a6%82%e4%bd%95%e5%81%9a%e8%bf%90%e7%bb%b4","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1183595.html","title":{"rendered":"python\u5982\u4f55\u505a\u8fd0\u7ef4"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25133307\/54bb8816-17b2-4a93-bdba-9a0623ee0a59.webp\" alt=\"python\u5982\u4f55\u505a\u8fd0\u7ef4\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u8fdb\u884c\u8fd0\u7ef4\u53ef\u4ee5\u901a\u8fc7<strong>\u81ea\u52a8\u5316\u7ba1\u7406\u3001\u76d1\u63a7\u7cfb\u7edf\u6027\u80fd\u3001\u65e5\u5fd7\u5206\u6790\u3001\u670d\u52a1\u5668\u914d\u7f6e\u7ba1\u7406<\/strong>\u7b49\u65b9\u5f0f\u5b9e\u73b0\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4f7f\u5f97\u8fd0\u7ef4\u5de5\u4f5c\u66f4\u52a0\u9ad8\u6548\u548c\u53ef\u9760\u3002\u5177\u4f53\u6765\u8bf4\uff0cPython\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e93\u548c\u6846\u67b6\uff0c\u5982Ansible\u3001Fabric\u3001SaltStack\u7b49\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5b9e\u73b0\u81ea\u52a8\u5316\u8fd0\u7ef4\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5229\u7528Python\u8fdb\u884c\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u81ea\u52a8\u5316\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>\u81ea\u52a8\u5316\u7ba1\u7406\u662f\u8fd0\u7ef4\u5de5\u4f5c\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0cPython\u901a\u8fc7\u5176\u5f3a\u5927\u7684\u5e93\u548c\u5de5\u5177\u4f7f\u5f97\u81ea\u52a8\u5316\u7ba1\u7406\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Ansible\u8fdb\u884c\u81ea\u52a8\u5316\u914d\u7f6e\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>Ansible\u662f\u4e00\u79cd\u5f00\u6e90\u7684\u81ea\u52a8\u5316\u5de5\u5177\uff0c\u4e3b\u8981\u7528\u4e8e\u8f6f\u4ef6\u914d\u7f6e\u7ba1\u7406\u3001\u5e94\u7528\u90e8\u7f72\u548c\u4efb\u52a1\u81ea\u52a8\u5316\u3002\u5b83\u7684\u914d\u7f6e\u6587\u4ef6\u4f7f\u7528YAML\u683c\u5f0f\uff0c\u975e\u5e38\u9002\u5408\u4e8ePython\u5f00\u53d1\u8005\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">- name: Ensure Apache is installed<\/p>\n<p>  apt:<\/p>\n<p>    name: apache2<\/p>\n<p>    state: present<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0YAML\u914d\u7f6e\u6587\u4ef6\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u76ee\u6807\u670d\u52a1\u5668\u4e0a\u5b89\u88c5Apache\u3002Ansible\u8fd8\u652f\u6301\u6a21\u5757\u5316\u7ba1\u7406\uff0c\u4f7f\u5f97\u590d\u6742\u7684\u8fd0\u7ef4\u4efb\u52a1\u4e5f\u80fd\u901a\u8fc7\u7b80\u5355\u7684\u811a\u672c\u6765\u5b8c\u6210\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Fabric\u8fdb\u884c\u8fdc\u7a0b\u6267\u884c\u548c\u90e8\u7f72<\/h4>\n<\/p>\n<p><p>Fabric\u662f\u4e00\u4e2a\u7528\u4e8ePython\u7684\u7b80\u5355\u7684\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u5b83\u7b80\u5316\u4e86SSH\u7684\u4f7f\u7528\uff0c\u4ece\u800c\u5b9e\u73b0\u8fdc\u7a0b\u6267\u884c\u548c\u90e8\u7f72\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from fabric import Connection<\/p>\n<p>def deploy():<\/p>\n<p>    conn = Connection(&#39;user@host&#39;)<\/p>\n<p>    conn.run(&#39;git pull&#39;)<\/p>\n<p>    conn.run(&#39;systemctl restart myapp&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Fabric\uff0c\u53ef\u4ee5\u5728\u591a\u4e2a\u670d\u52a1\u5668\u4e0a\u6267\u884c\u8fdc\u7a0b\u547d\u4ee4\uff0c\u8f7b\u677e\u5b9e\u73b0\u4ee3\u7801\u7684\u66f4\u65b0\u548c\u5e94\u7528\u7684\u91cd\u542f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u76d1\u63a7\u7cfb\u7edf\u6027\u80fd<\/h3>\n<\/p>\n<p><p>\u7cfb\u7edf\u6027\u80fd\u76d1\u63a7\u662f\u786e\u4fdd\u7cfb\u7edf\u7a33\u5b9a\u8fd0\u884c\u7684\u91cd\u8981\u624b\u6bb5\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5e93\u548c\u5de5\u5177\u6765\u5b9e\u73b0\u6027\u80fd\u76d1\u63a7\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528psutil\u5e93\u8fdb\u884c\u7cfb\u7edf\u76d1\u63a7<\/h4>\n<\/p>\n<p><p>psutil\u662f\u4e00\u4e2a\u8de8\u5e73\u53f0\u5e93\uff0c\u7528\u4e8e\u68c0\u7d22\u7cfb\u7edf\u5229\u7528\u7387\uff08CPU\u3001\u5185\u5b58\u3001\u78c1\u76d8\u3001\u7f51\u7edc\u3001\u4f20\u611f\u5668\uff09\u7684\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import psutil<\/p>\n<h2><strong>\u83b7\u53d6CPU\u4f7f\u7528\u7387<\/strong><\/h2>\n<p>print(psutil.cpu_percent(interval=1))<\/p>\n<h2><strong>\u83b7\u53d6\u5185\u5b58\u4f7f\u7528\u60c5\u51b5<\/strong><\/h2>\n<p>print(psutil.virtual_memory())<\/p>\n<h2><strong>\u83b7\u53d6\u78c1\u76d8\u4f7f\u7528\u60c5\u51b5<\/strong><\/h2>\n<p>print(psutil.disk_usage(&#39;\/&#39;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7psutil\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u83b7\u53d6\u7cfb\u7edf\u7684\u5404\u9879\u6027\u80fd\u6307\u6807\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u62a5\u8b66\u548c\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Prometheus\u8fdb\u884c\u76d1\u63a7\u548c\u62a5\u8b66<\/h4>\n<\/p>\n<p><p>Prometheus\u662f\u4e00\u79cd\u5f00\u6e90\u7684\u76d1\u63a7\u7cfb\u7edf\u548c\u62a5\u8b66\u5de5\u5177\uff0cPython\u53ef\u4ee5\u901a\u8fc7Prometheus\u5ba2\u6237\u7aef\u5e93\u6765\u53d1\u9001\u76d1\u63a7\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from prometheus_client import start_http_server, Gauge<\/p>\n<p>import random<\/p>\n<p>import time<\/p>\n<p>g = Gauge(&#39;random_value&#39;, &#39;Random value&#39;)<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    start_http_server(8000)<\/p>\n<p>    while True:<\/p>\n<p>        g.set(random.random())<\/p>\n<p>        time.sleep(1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u4ee3\u7801\uff0c\u53ef\u4ee5\u5c06\u968f\u673a\u751f\u6210\u7684\u6570\u636e\u53d1\u9001\u5230Prometheus\u8fdb\u884c\u76d1\u63a7\uff0c\u5e76\u5728Prometheus\u4e2d\u8bbe\u7f6e\u62a5\u8b66\u89c4\u5219\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u65e5\u5fd7\u5206\u6790<\/h3>\n<\/p>\n<p><p>\u65e5\u5fd7\u5206\u6790\u662f\u8fd0\u7ef4\u5de5\u4f5c\u7684\u53e6\u4e00\u4e2a\u91cd\u8981\u65b9\u9762\uff0c\u901a\u8fc7\u5206\u6790\u65e5\u5fd7\u53ef\u4ee5\u53d1\u73b0\u7cfb\u7edf\u6f5c\u5728\u7684\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Loguru\u8fdb\u884c\u65e5\u5fd7\u5904\u7406<\/h4>\n<\/p>\n<p><p>Loguru\u662f\u4e00\u4e2a\u7b80\u6d01\u4e14\u529f\u80fd\u5f3a\u5927\u7684Python\u65e5\u5fd7\u5e93\uff0c\u9002\u5408\u5feb\u901f\u5f00\u53d1\u548c\u8c03\u8bd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from loguru import logger<\/p>\n<p>logger.add(&quot;file.log&quot;, rotation=&quot;500 MB&quot;)<\/p>\n<p>logger.debug(&quot;This is a debug message&quot;)<\/p>\n<p>logger.info(&quot;This is an info message&quot;)<\/p>\n<p>logger.error(&quot;This is an error message&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Loguru\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06\u65e5\u5fd7\u8f93\u51fa\u5230\u6587\u4ef6\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u65e5\u5fd7\u7684\u8f6e\u8f6c\u548c\u5f52\u6863\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528ElasticSearch\u8fdb\u884c\u65e5\u5fd7\u5b58\u50a8\u548c\u5206\u6790<\/h4>\n<\/p>\n<p><p>ElasticSearch\u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u641c\u7d22\u548c\u5206\u6790\u5f15\u64ce\uff0c\u9002\u5408\u5927\u89c4\u6a21\u7684\u65e5\u5fd7\u6570\u636e\u5b58\u50a8\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from elasticsearch import Elasticsearch<\/p>\n<p>es = Elasticsearch()<\/p>\n<p>doc = {<\/p>\n<p>    &#39;author&#39;: &#39;kimchy&#39;,<\/p>\n<p>    &#39;text&#39;: &#39;Elasticsearch: cool. bonsai cool.&#39;,<\/p>\n<p>    &#39;timestamp&#39;: datetime.now(),<\/p>\n<p>}<\/p>\n<p>res = es.index(index=&quot;test-index&quot;, id=1, body=doc)<\/p>\n<p>print(res[&#39;result&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7ElasticSearch\uff0c\u53ef\u4ee5\u5c06\u65e5\u5fd7\u6570\u636e\u5b58\u50a8\u5230ElasticSearch\u96c6\u7fa4\u4e2d\uff0c\u5e76\u4f7f\u7528Kibana\u7b49\u5de5\u5177\u8fdb\u884c\u53ef\u89c6\u5316\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u670d\u52a1\u5668\u914d\u7f6e\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>\u670d\u52a1\u5668\u914d\u7f6e\u7ba1\u7406\u662f\u786e\u4fdd\u670d\u52a1\u5668\u5b89\u5168\u548c\u7a33\u5b9a\u8fd0\u884c\u7684\u5173\u952e\u3002Python\u53ef\u4ee5\u901a\u8fc7\u81ea\u52a8\u5316\u811a\u672c\u548c\u5de5\u5177\u6765\u5b9e\u73b0\u670d\u52a1\u5668\u914d\u7f6e\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528SaltStack\u8fdb\u884c\u914d\u7f6e\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>SaltStack\u662f\u4e00\u4e2a\u57fa\u7840\u8bbe\u65bd\u81ea\u52a8\u5316\u5e73\u53f0\uff0c\u63d0\u4f9b\u4e86\u914d\u7f6e\u7ba1\u7406\u3001\u8fdc\u7a0b\u6267\u884c\u548c\u4e91\u7ba1\u7406\u7b49\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b89\u88c5SaltStack<\/p>\n<p>sudo apt-get install salt-master salt-minion<\/p>\n<h2><strong>\u914d\u7f6eSaltStack<\/strong><\/h2>\n<p>echo &quot;master: salt-master&quot; &gt; \/etc\/salt\/minion<\/p>\n<h2><strong>\u4f7f\u7528SaltStack\u8fdb\u884c\u914d\u7f6e\u7ba1\u7406<\/strong><\/h2>\n<p>salt &#39;*&#39; test.ping<\/p>\n<p>salt &#39;*&#39; pkg.install apache2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7SaltStack\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5728\u5927\u89c4\u6a21\u670d\u52a1\u5668\u96c6\u7fa4\u4e2d\u8fdb\u884c\u914d\u7f6e\u7ba1\u7406\u548c\u5e94\u7528\u90e8\u7f72\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Chef\u8fdb\u884c\u57fa\u7840\u8bbe\u65bd\u5373\u4ee3\u7801\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>Chef\u662f\u4e00\u4e2a\u57fa\u7840\u8bbe\u65bd\u5373\u4ee3\u7801\uff08Infrastructure as Code\uff09\u5de5\u5177\uff0c\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u4ee3\u7801\u6765\u7ba1\u7406\u670d\u52a1\u5668\u914d\u7f6e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-ruby\"># Chef Recipe<\/p>\n<p>package &#39;apache2&#39; do<\/p>\n<p>  action :install<\/p>\n<p>end<\/p>\n<p>service &#39;apache2&#39; do<\/p>\n<p>  action [:enable, :start]<\/p>\n<p>end<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Chef\uff0c\u53ef\u4ee5\u5c06\u670d\u52a1\u5668\u914d\u7f6e\u7ba1\u7406\u4f5c\u4e3a\u4ee3\u7801\u8fdb\u884c\u7248\u672c\u63a7\u5236\u548c\u7ba1\u7406\uff0c\u63d0\u9ad8\u914d\u7f6e\u7ba1\u7406\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u53ef\u9760\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u7f51\u7edc\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>\u7f51\u7edc\u7ba1\u7406\u5728\u8fd0\u7ef4\u5de5\u4f5c\u4e2d\u540c\u6837\u91cd\u8981\uff0cPython\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u5de5\u5177\u548c\u5e93\u6765\u5b9e\u73b0\u7f51\u7edc\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Scapy\u8fdb\u884c\u7f51\u7edc\u6570\u636e\u5305\u5904\u7406<\/h4>\n<\/p>\n<p><p>Scapy\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u7f51\u7edc\u6570\u636e\u5305\u5904\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4e8e\u7f51\u7edc\u626b\u63cf\u3001\u6570\u636e\u5305\u89e3\u6790\u548c\u751f\u6210\u7b49\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from scapy.all import *<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aICMP\u6570\u636e\u5305<\/strong><\/h2>\n<p>packet = IP(dst=&quot;8.8.8.8&quot;)\/ICMP()<\/p>\n<h2><strong>\u53d1\u9001\u6570\u636e\u5305\u5e76\u63a5\u6536\u54cd\u5e94<\/strong><\/h2>\n<p>response = sr1(packet)<\/p>\n<p>print(response.show())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Scapy\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u7f51\u7edc\u6570\u636e\u5305\u7684\u5904\u7406\u548c\u5206\u6790\uff0c\u9002\u7528\u4e8e\u7f51\u7edc\u6545\u969c\u6392\u67e5\u548c\u5b89\u5168\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Netmiko\u8fdb\u884c\u7f51\u7edc\u8bbe\u5907\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>Netmiko\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406\u7f51\u7edc\u8bbe\u5907\u7684Python\u5e93\uff0c\u652f\u6301\u591a\u79cd\u7f51\u7edc\u8bbe\u5907\u548c\u534f\u8bae\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from netmiko import ConnectHandler<\/p>\n<p>cisco = {<\/p>\n<p>    &#39;device_type&#39;: &#39;cisco_ios&#39;,<\/p>\n<p>    &#39;host&#39;: &#39;192.168.1.1&#39;,<\/p>\n<p>    &#39;username&#39;: &#39;admin&#39;,<\/p>\n<p>    &#39;password&#39;: &#39;password&#39;,<\/p>\n<p>}<\/p>\n<p>net_connect = ConnectHandler(cisco)<\/p>\n<p>output = net_connect.send_command(&#39;show ip int brief&#39;)<\/p>\n<p>print(output)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Netmiko\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fde\u63a5\u548c\u7ba1\u7406\u7f51\u7edc\u8bbe\u5907\uff0c\u5b9e\u73b0\u81ea\u52a8\u5316\u914d\u7f6e\u548c\u76d1\u63a7\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u6570\u636e\u5e93\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>\u6570\u636e\u5e93\u7ba1\u7406\u662f\u8fd0\u7ef4\u5de5\u4f5c\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u5e93\u548c\u5de5\u5177\u6765\u5b9e\u73b0\u6570\u636e\u5e93\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528SQLAlchemy\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>SQLAlchemy\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684Python SQL\u5de5\u5177\u5305\u548c\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff08ORM\uff09\u5e93\uff0c\u9002\u7528\u4e8e\u591a\u79cd\u6570\u636e\u5e93\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import create_engine<\/p>\n<p>from sqlalchemy.orm import sessionmaker<\/p>\n<p>engine = create_engine(&#39;sqlite:\/\/\/example.db&#39;)<\/p>\n<p>Session = sessionmaker(bind=engine)<\/p>\n<p>session = Session()<\/p>\n<h2><strong>\u521b\u5efa\u8868<\/strong><\/h2>\n<p>from sqlalchemy import Column, Integer, String, Base<\/p>\n<p>class User(Base):<\/p>\n<p>    __tablename__ = &#39;users&#39;<\/p>\n<p>    id = Column(Integer, primary_key=True)<\/p>\n<p>    name = Column(String)<\/p>\n<p>Base.metadata.create_all(engine)<\/p>\n<h2><strong>\u63d2\u5165\u6570\u636e<\/strong><\/h2>\n<p>new_user = User(name=&#39;John Doe&#39;)<\/p>\n<p>session.add(new_user)<\/p>\n<p>session.commit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7SQLAlchemy\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u5e93\u7684\u521b\u5efa\u3001\u67e5\u8be2\u548c\u7ba1\u7406\uff0c\u5b9e\u73b0\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u81ea\u52a8\u5316\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528PyMySQL\u8fdb\u884cMySQL\u6570\u636e\u5e93\u64cd\u4f5c<\/h4>\n<\/p>\n<p><p>PyMySQL\u662f\u4e00\u4e2a\u7eafPython\u5b9e\u73b0\u7684MySQL\u5ba2\u6237\u7aef\u5e93\uff0c\u9002\u7528\u4e8eMySQL\u6570\u636e\u5e93\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pymysql<\/p>\n<h2><strong>\u8fde\u63a5\u6570\u636e\u5e93<\/strong><\/h2>\n<p>connection = pymysql.connect(host=&#39;localhost&#39;,<\/p>\n<p>                             user=&#39;user&#39;,<\/p>\n<p>                             password=&#39;passwd&#39;,<\/p>\n<p>                             database=&#39;db&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u6e38\u6807<\/strong><\/h2>\n<p>cursor = connection.cursor()<\/p>\n<h2><strong>\u6267\u884c\u67e5\u8be2<\/strong><\/h2>\n<p>cursor.execute(&quot;SELECT * FROM users&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u7ed3\u679c<\/strong><\/h2>\n<p>result = cursor.fetchall()<\/p>\n<p>print(result)<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>connection.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7PyMySQL\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884cMySQL\u6570\u636e\u5e93\u7684\u8fde\u63a5\u548c\u64cd\u4f5c\uff0c\u9002\u7528\u4e8e\u5404\u79cdMySQL\u6570\u636e\u5e93\u7ba1\u7406\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5907\u4efd\u548c\u6062\u590d<\/h3>\n<\/p>\n<p><p>\u5907\u4efd\u548c\u6062\u590d\u662f\u8fd0\u7ef4\u5de5\u4f5c\u4e2d\u786e\u4fdd\u6570\u636e\u5b89\u5168\u548c\u7cfb\u7edf\u7a33\u5b9a\u7684\u91cd\u8981\u624b\u6bb5\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u5de5\u5177\u548c\u5e93\u6765\u5b9e\u73b0\u5907\u4efd\u548c\u6062\u590d\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528shutil\u5e93\u8fdb\u884c\u6587\u4ef6\u5907\u4efd<\/h4>\n<\/p>\n<p><p>shutil\u662fPython\u6807\u51c6\u5e93\u4e2d\u7684\u4e00\u4e2a\u6587\u4ef6\u64cd\u4f5c\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u6587\u4ef6\u7684\u590d\u5236\u3001\u79fb\u52a8\u548c\u5220\u9664\u7b49\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import shutil<\/p>\n<h2><strong>\u5907\u4efd\u6587\u4ef6<\/strong><\/h2>\n<p>shutil.copy(&#39;source_file&#39;, &#39;backup_file&#39;)<\/p>\n<h2><strong>\u5907\u4efd\u76ee\u5f55<\/strong><\/h2>\n<p>shutil.copytree(&#39;source_directory&#39;, &#39;backup_directory&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7shutil\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u6587\u4ef6\u548c\u76ee\u5f55\u7684\u5907\u4efd\uff0c\u786e\u4fdd\u6570\u636e\u7684\u5b89\u5168\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Boto3\u8fdb\u884c\u4e91\u7aef\u5907\u4efd<\/h4>\n<\/p>\n<p><p>Boto3\u662fAmazon Web Services (AWS) \u7684Python SDK\uff0c\u53ef\u4ee5\u7528\u4e8e\u7ba1\u7406AWS\u670d\u52a1\uff0c\u5982S3\u5b58\u50a8\u670d\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import boto3<\/p>\n<p>s3 = boto3.client(&#39;s3&#39;)<\/p>\n<h2><strong>\u4e0a\u4f20\u6587\u4ef6\u5230S3<\/strong><\/h2>\n<p>s3.upload_file(&#39;backup_file&#39;, &#39;mybucket&#39;, &#39;backup_file&#39;)<\/p>\n<h2><strong>\u4e0b\u8f7d\u6587\u4ef6\u4eceS3<\/strong><\/h2>\n<p>s3.download_file(&#39;mybucket&#39;, &#39;backup_file&#39;, &#39;restore_file&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Boto3\uff0c\u53ef\u4ee5\u5c06\u5907\u4efd\u6587\u4ef6\u4e0a\u4f20\u5230\u4e91\u5b58\u50a8\u670d\u52a1\uff0c\u5b9e\u73b0\u4e91\u7aef\u5907\u4efd\u548c\u6062\u590d\uff0c\u63d0\u9ad8\u6570\u636e\u7684\u5b89\u5168\u6027\u548c\u53ef\u7528\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u5b89\u5168\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>\u5b89\u5168\u7ba1\u7406\u662f\u8fd0\u7ef4\u5de5\u4f5c\u7684\u91cd\u4e2d\u4e4b\u91cd\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u5de5\u5177\u548c\u5e93\u6765\u5b9e\u73b0\u5b89\u5168\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Paramiko\u8fdb\u884cSSH\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>Paramiko\u662f\u4e00\u4e2a\u7528\u4e8ePython\u7684SSHv2\u534f\u8bae\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u8fdc\u7a0b\u670d\u52a1\u5668\u7684\u7ba1\u7406\u548c\u81ea\u52a8\u5316\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import paramiko<\/p>\n<h2><strong>\u521b\u5efaSSH\u5ba2\u6237\u7aef<\/strong><\/h2>\n<p>ssh = paramiko.SSHClient()<\/p>\n<p>ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())<\/p>\n<h2><strong>\u8fde\u63a5\u670d\u52a1\u5668<\/strong><\/h2>\n<p>ssh.connect(&#39;hostname&#39;, username=&#39;user&#39;, password=&#39;passwd&#39;)<\/p>\n<h2><strong>\u6267\u884c\u547d\u4ee4<\/strong><\/h2>\n<p>stdin, stdout, stderr = ssh.exec_command(&#39;ls -l&#39;)<\/p>\n<p>print(stdout.read().decode())<\/p>\n<h2><strong>\u5173\u95ed\u8fde\u63a5<\/strong><\/h2>\n<p>ssh.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Paramiko\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u8fdc\u7a0b\u670d\u52a1\u5668\u7684\u7ba1\u7406\u548c\u64cd\u4f5c\uff0c\u5b9e\u73b0\u5b89\u5168\u7684\u81ea\u52a8\u5316\u8fd0\u7ef4\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Cryptography\u8fdb\u884c\u6570\u636e\u52a0\u5bc6<\/h4>\n<\/p>\n<p><p>Cryptography\u662f\u4e00\u4e2a\u7528\u4e8e\u52a0\u5bc6\u548c\u89e3\u5bc6\u7684Python\u5e93\uff0c\u652f\u6301\u591a\u79cd\u52a0\u5bc6\u7b97\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from cryptography.fernet import Fernet<\/p>\n<h2><strong>\u751f\u6210\u5bc6\u94a5<\/strong><\/h2>\n<p>key = Fernet.generate_key()<\/p>\n<p>cipher_suite = Fernet(key)<\/p>\n<h2><strong>\u52a0\u5bc6\u6570\u636e<\/strong><\/h2>\n<p>cipher_text = cipher_suite.encrypt(b&quot;Hello, World!&quot;)<\/p>\n<p>print(cipher_text)<\/p>\n<h2><strong>\u89e3\u5bc6\u6570\u636e<\/strong><\/h2>\n<p>plain_text = cipher_suite.decrypt(cipher_text)<\/p>\n<p>print(plain_text.decode())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Cryptography\u5e93\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5b9e\u73b0\u6570\u636e\u7684\u52a0\u5bc6\u548c\u89e3\u5bc6\uff0c\u786e\u4fdd\u6570\u636e\u7684\u5b89\u5168\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u5bb9\u5668\u7ba1\u7406<\/h3>\n<\/p>\n<p><p>\u5bb9\u5668\u7ba1\u7406\u662f\u73b0\u4ee3\u8fd0\u7ef4\u5de5\u4f5c\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u65b9\u9762\uff0cPython\u63d0\u4f9b\u4e86\u591a\u79cd\u5de5\u5177\u548c\u5e93\u6765\u5b9e\u73b0\u5bb9\u5668\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Docker SDK\u8fdb\u884c\u5bb9\u5668\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>Docker SDK\u662fDocker\u63d0\u4f9b\u7684Python\u5ba2\u6237\u7aef\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u7ba1\u7406Docker\u5bb9\u5668\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import docker<\/p>\n<p>client = docker.from_env()<\/p>\n<h2><strong>\u521b\u5efa\u5bb9\u5668<\/strong><\/h2>\n<p>container = client.containers.run(&quot;ubuntu&quot;, &quot;echo hello world&quot;, detach=True)<\/p>\n<p>print(container.logs())<\/p>\n<h2><strong>\u505c\u6b62\u5bb9\u5668<\/strong><\/h2>\n<p>container.stop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Docker SDK\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u521b\u5efa\u3001\u7ba1\u7406\u548c\u76d1\u63a7Docker\u5bb9\u5668\uff0c\u5b9e\u73b0\u5bb9\u5668\u5316\u5e94\u7528\u7684\u81ea\u52a8\u5316\u8fd0\u7ef4\u3002<\/p>\n<\/p>\n<p><h4>2. \u4f7f\u7528Kubernetes\u5ba2\u6237\u7aef\u8fdb\u884c\u96c6\u7fa4\u7ba1\u7406<\/h4>\n<\/p>\n<p><p>Kubernetes\u5ba2\u6237\u7aef\u662f\u4e00\u4e2a\u7528\u4e8e\u7ba1\u7406Kubernetes\u96c6\u7fa4\u7684Python\u5e93\uff0c\u53ef\u4ee5\u7528\u4e8e\u5bb9\u5668\u7f16\u6392\u548c\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kubernetes import client, config<\/p>\n<h2><strong>\u52a0\u8f7d\u914d\u7f6e<\/strong><\/h2>\n<p>config.load_kube_config()<\/p>\n<h2><strong>\u521b\u5efaAPI\u5b9e\u4f8b<\/strong><\/h2>\n<p>v1 = client.CoreV1Api()<\/p>\n<h2><strong>\u83b7\u53d6\u6240\u6709Pod<\/strong><\/h2>\n<p>pods = v1.list_pod_for_all_namespaces(watch=False)<\/p>\n<p>for pod in pods.items:<\/p>\n<p>    print(f&quot;{pod.metadata.namespace} - {pod.metadata.name}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7Kubernetes\u5ba2\u6237\u7aef\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ba1\u7406Kubernetes\u96c6\u7fa4\uff0c\u5b9e\u73b0\u5bb9\u5668\u5316\u5e94\u7528\u7684\u7f16\u6392\u548c\u7ba1\u7406\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u8fd0\u7ef4\u81ea\u52a8\u5316\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u8fd0\u7ef4\u81ea\u52a8\u5316\u811a\u672c\u662f\u63d0\u9ad8\u8fd0\u7ef4\u6548\u7387\u7684\u91cd\u8981\u5de5\u5177\uff0cPython\u901a\u8fc7\u5176\u7b80\u6d01\u7684\u8bed\u6cd5\u548c\u5f3a\u5927\u7684\u5e93\u652f\u6301\uff0c\u4f7f\u5f97\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u53d8\u5f97\u66f4\u52a0\u5bb9\u6613\u3002<\/p>\n<\/p>\n<p><h4>1. \u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u793a\u4f8b<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import subprocess<\/p>\n<p>def backup_files():<\/p>\n<p>    source = &#39;\/path\/to\/source&#39;<\/p>\n<p>    destination = &#39;\/path\/to\/destination&#39;<\/p>\n<p>    subprocess.run([&#39;rsync&#39;, &#39;-av&#39;, source, destination])<\/p>\n<p>def update_system():<\/p>\n<p>    subprocess.run([&#39;sudo&#39;, &#39;apt-get&#39;, &#39;update&#39;])<\/p>\n<p>    subprocess.run([&#39;sudo&#39;, &#39;apt-get&#39;, &#39;upgrade&#39;, &#39;-y&#39;])<\/p>\n<p>def deploy_application():<\/p>\n<p>    os.chdir(&#39;\/path\/to\/application&#39;)<\/p>\n<p>    subprocess.run([&#39;git&#39;, &#39;pull&#39;])<\/p>\n<p>    subprocess.run([&#39;systemctl&#39;, &#39;restart&#39;, &#39;application&#39;])<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    backup_files()<\/p>\n<p>    update_system()<\/p>\n<p>    deploy_application()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u793a\u4f8b\uff0c\u53ef\u4ee5\u770b\u5230\u5982\u4f55\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u8fd0\u7ef4\u81ea\u52a8\u5316\u811a\u672c\uff0c\u5b9e\u73b0\u6587\u4ef6\u5907\u4efd\u3001\u7cfb\u7edf\u66f4\u65b0\u548c\u5e94\u7528\u90e8\u7f72\u3002<\/p>\n<\/p>\n<p><h4>2. \u5b9a\u65f6\u6267\u884c\u81ea\u52a8\u5316\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528cron\u6216\u5176\u4ed6\u5b9a\u65f6\u4efb\u52a1\u8c03\u5ea6\u5de5\u5177\u6765\u5b9a\u65f6\u6267\u884c\u81ea\u52a8\u5316\u811a\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\"># \u7f16\u8f91crontab<\/p>\n<p>crontab -e<\/p>\n<h2><strong>\u6dfb\u52a0\u5b9a\u65f6\u4efb\u52a1<\/strong><\/h2>\n<p>0 2 * * * \/usr\/bin\/python3 \/path\/to\/script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u5b9a\u65f6\u4efb\u52a1\uff0c\u53ef\u4ee5\u5b9a\u671f\u6267\u884c\u81ea\u52a8\u5316\u811a\u672c\uff0c\u5b9e\u73b0\u8fd0\u7ef4\u4efb\u52a1\u7684\u81ea\u52a8\u5316\u548c\u65e0\u4eba\u503c\u5b88\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3\uff0cPython\u5728\u8fd0\u7ef4\u5de5\u4f5c\u4e2d\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\uff0c\u901a\u8fc7\u81ea\u52a8\u5316\u7ba1\u7406\u3001\u76d1\u63a7\u7cfb\u7edf\u6027\u80fd\u3001\u65e5\u5fd7\u5206\u6790\u3001\u670d\u52a1\u5668\u914d\u7f6e\u7ba1\u7406\u3001\u7f51\u7edc\u7ba1\u7406\u3001\u6570\u636e\u5e93\u7ba1\u7406\u3001\u5907\u4efd\u548c\u6062\u590d\u3001\u5b89\u5168\u7ba1\u7406\u3001\u5bb9\u5668\u7ba1\u7406\u548c\u8fd0\u7ef4\u81ea\u52a8\u5316\u811a\u672c\u7b49\u591a\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u8fd0\u7ef4\u5de5\u4f5c\u7684\u6548\u7387\u548c\u53ef\u9760\u6027\u3002Python\u7684\u7b80\u6d01\u8bed\u6cd5\u548c\u5f3a\u5927\u5e93\u652f\u6301\uff0c\u4f7f\u5f97\u5b83\u6210\u4e3a\u8fd0\u7ef4\u5de5\u4f5c\u4e2d\u7684\u5f97\u529b\u52a9\u624b\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u81ea\u52a8\u5316\u8fd0\u7ef4\u4efb\u52a1\uff1f<\/strong><br \/>Python\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u811a\u672c\u6765\u5b9e\u73b0\u81ea\u52a8\u5316\u8fd0\u7ef4\u4efb\u52a1\uff0c\u4f8b\u5982\u5b9a\u671f\u5907\u4efd\u3001\u65e5\u5fd7\u5206\u6790\u548c\u7cfb\u7edf\u76d1\u63a7\u3002\u4f7f\u7528Python\u7684\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u6a21\u5757\uff08\u5982Paramiko\u3001Fabric\u548cAnsible\uff09\u53ef\u4ee5\u5e2e\u52a9\u7b80\u5316\u8fd9\u4e9b\u4efb\u52a1\u3002\u901a\u8fc7\u7f16\u5199\u76f8\u5e94\u7684\u811a\u672c\uff0c\u4f60\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u6267\u884c\u3001\u8fdc\u7a0b\u7ba1\u7406\u548c\u5b9a\u65f6\u8c03\u5ea6\u7b49\u529f\u80fd\uff0c\u663e\u8457\u63d0\u5347\u8fd0\u7ef4\u6548\u7387\u3002<\/p>\n<p><strong>Python\u5728\u8fd0\u7ef4\u76d1\u63a7\u4e2d\u7684\u5e94\u7528\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5728\u8fd0\u7ef4\u76d1\u63a7\u65b9\u9762\uff0cPython\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u76d1\u63a7\u5de5\u5177\uff08\u5982Prometheus\u548cGrafana\uff09\u8fdb\u884c\u6570\u636e\u6536\u96c6\u548c\u53ef\u89c6\u5316\u3002\u53ef\u4ee5\u7f16\u5199Python\u811a\u672c\u6765\u83b7\u53d6\u7cfb\u7edf\u6027\u80fd\u6307\u6807\uff08\u5982CPU\u3001\u5185\u5b58\u548c\u78c1\u76d8\u4f7f\u7528\u60c5\u51b5\uff09\uff0c\u5e76\u5c06\u8fd9\u4e9b\u6570\u636e\u53d1\u9001\u5230\u76d1\u63a7\u7cfb\u7edf\u3002\u6b64\u5916\uff0cPython\u8fd8\u53ef\u4ee5\u96c6\u6210API\u8c03\u7528\uff0c\u83b7\u53d6\u4e91\u670d\u52a1\u6216\u5176\u4ed6\u7b2c\u4e09\u65b9\u670d\u52a1\u7684\u5065\u5eb7\u72b6\u6001\uff0c\u5e2e\u52a9\u8fd0\u7ef4\u4eba\u5458\u5b9e\u65f6\u4e86\u89e3\u7cfb\u7edf\u8fd0\u884c\u60c5\u51b5\u3002<\/p>\n<p><strong>\u8fd0\u7ef4\u4eba\u5458\u5b66\u4e60Python\u7684\u6700\u4f73\u8d44\u6e90\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u8fd0\u7ef4\u4eba\u5458\u5b66\u4e60Python\u7684\u8d44\u6e90\u76f8\u5f53\u4e30\u5bcc\uff0c\u53ef\u4ee5\u4ece\u5728\u7ebf\u8bfe\u7a0b\uff08\u5982Coursera\u3001Udemy\u548cedX\uff09\u5165\u624b\uff0c\u9009\u62e9\u4e13\u6ce8\u4e8e\u8fd0\u7ef4\u548c\u81ea\u52a8\u5316\u7684\u8bfe\u7a0b\u3002\u6b64\u5916\uff0c\u9605\u8bfb\u76f8\u5173\u4e66\u7c4d\uff08\u5982\u300aPython\u7f51\u7edc\u7f16\u7a0b\u300b\u6216\u300aAutomate the Boring Stuff with Python\u300b\uff09\u4e5f\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002\u7ed3\u5408\u5b9e\u8df5\u9879\u76ee\uff0c\u80fd\u591f\u66f4\u597d\u5730\u638c\u63e1Python\u5728\u8fd0\u7ef4\u4e2d\u7684\u5e94\u7528\uff0c\u63d0\u5347\u6280\u672f\u80fd\u529b\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8fdb\u884c\u8fd0\u7ef4\u53ef\u4ee5\u901a\u8fc7\u81ea\u52a8\u5316\u7ba1\u7406\u3001\u76d1\u63a7\u7cfb\u7edf\u6027\u80fd\u3001\u65e5\u5fd7\u5206\u6790\u3001\u670d\u52a1\u5668\u914d\u7f6e\u7ba1\u7406\u7b49\u65b9\u5f0f\u5b9e\u73b0\u3002\u8fd9\u4e9b\u65b9\u6cd5\u4f7f\u5f97\u8fd0\u7ef4 [&hellip;]","protected":false},"author":3,"featured_media":1183604,"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\/1183595"}],"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=1183595"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183595\/revisions"}],"predecessor-version":[{"id":1183605,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1183595\/revisions\/1183605"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1183604"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1183595"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1183595"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1183595"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}