{"id":1178084,"date":"2025-01-15T18:06:04","date_gmt":"2025-01-15T10:06:04","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1178084.html"},"modified":"2025-01-15T18:06:06","modified_gmt":"2025-01-15T10:06:06","slug":"python%e5%a6%82%e4%bd%95%e9%87%8d%e6%96%b0%e8%bf%90%e8%a1%8c%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1178084.html","title":{"rendered":"python\u5982\u4f55\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25112830\/e0b7adc5-300d-4706-8888-82dece13c028.webp\" alt=\"python\u5982\u4f55\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\" \/><\/p>\n<p><p> <strong>Python\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u3001while\u5faa\u73af\u3001\u91cd\u542fPython\u89e3\u91ca\u5668\u3001\u4f7f\u7528\u5916\u90e8\u811a\u672c\u7b49\u65b9\u6cd5\u3002<\/strong>\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u5728\u7a0b\u5e8f\u4e2d\u5d4c\u5957\u5faa\u73af\u6216\u9012\u5f52\u8c03\u7528\u81ea\u5df1\uff0c\u4f8b\u5982\u5728\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\u540e\uff0c\u901a\u8fc7\u4e00\u4e2a\u8be2\u95ee\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7684\u8f93\u5165\u6765\u51b3\u5b9a\u662f\u5426\u518d\u6b21\u8fd0\u884c\u3002<strong>\u4f7f\u7528while\u5faa\u73af<\/strong>\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5b9e\u73b0\u8fd9\u4e2a\u529f\u80fd\uff0c\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e2a\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528while\u5faa\u73af\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528while\u5faa\u73af\u662f\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u7684\u5e38\u89c1\u65b9\u5f0f\u3002\u5728\u7a0b\u5e8f\u7684\u6700\u540e\u90e8\u5206\u6dfb\u52a0\u4e00\u4e2a\u5faa\u73af\uff0c\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u5982\u679c\u7528\u6237\u9009\u62e9\u91cd\u65b0\u8fd0\u884c\uff0c\u5219\u901a\u8fc7continue\u8bed\u53e5\u8df3\u8f6c\u5230\u5faa\u73af\u7684\u5f00\u5934\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>while True:<\/p>\n<p>    main_program()<\/p>\n<p>    answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>    if answer != &#39;y&#39;:<\/p>\n<p>        break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>main_program<\/code>\u51fd\u6570\u5305\u542b\u4e86\u4f60\u7684\u4e3b\u8981\u4ee3\u7801\u3002\u5728while\u5faa\u73af\u5185\uff0c\u6bcf\u6b21\u8fd0\u884c\u5b8c\u4e3b\u7a0b\u5e8f\u540e\uff0c\u7528\u6237\u4f1a\u88ab\u8be2\u95ee\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u5982\u679c\u7528\u6237\u8f93\u5165\u201cy\u201d\uff0c\u7a0b\u5e8f\u4f1a\u91cd\u65b0\u5f00\u59cb\uff0c\u5426\u5219\u7a0b\u5e8f\u5c06\u7ed3\u675f\u3002<\/p>\n<\/p>\n<p><h4>\u8be6\u7ec6\u63cf\u8ff0\uff1a<\/h4>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b9a\u4e49\u4e3b\u7a0b\u5e8f\u51fd\u6570<\/strong>\uff1a\u9996\u5148\u5b9a\u4e49\u4e00\u4e2a\u5305\u542b\u4e3b\u8981\u4ee3\u7801\u903b\u8f91\u7684\u51fd\u6570\uff0c\u4f8b\u5982<code>main_program<\/code>\u3002\u8fd9\u4e2a\u51fd\u6570\u53ef\u4ee5\u5305\u542b\u4efb\u4f55\u4f60\u9700\u8981\u8fd0\u884c\u7684\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528while\u5faa\u73af<\/strong>\uff1a\u5728\u4e3b\u7a0b\u5e8f\u5916\u90e8\u4f7f\u7528\u4e00\u4e2a\u65e0\u9650\u7684while\u5faa\u73af<code>while True:<\/code>\u3002\u8fd9\u6837\u5faa\u73af\u4f1a\u4e00\u76f4\u8fd0\u884c\uff0c\u76f4\u5230\u624b\u52a8\u4e2d\u65ad\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8c03\u7528\u4e3b\u7a0b\u5e8f\u51fd\u6570<\/strong>\uff1a\u5728while\u5faa\u73af\u5185\u8c03\u7528<code>main_program<\/code>\u51fd\u6570\u6765\u8fd0\u884c\u4e3b\u8981\u4ee3\u7801\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c<\/strong>\uff1a\u5728\u4e3b\u7a0b\u5e8f\u8fd0\u884c\u7ed3\u675f\u540e\uff0c\u4f7f\u7528<code>input()<\/code>\u51fd\u6570\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff0c\u5e76\u5c06\u8f93\u5165\u8f6c\u6362\u4e3a\u5c0f\u5199\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u68c0\u67e5\u7528\u6237\u8f93\u5165<\/strong>\uff1a\u5982\u679c\u7528\u6237\u8f93\u5165\u201cy\u201d\uff0c\u5219\u7ee7\u7eed\u5faa\u73af\uff0c\u91cd\u65b0\u8fd0\u884c\u4e3b\u7a0b\u5e8f\u3002\u5982\u679c\u8f93\u5165\u5176\u4ed6\u5185\u5bb9\uff0c\u4f7f\u7528<code>break<\/code>\u8bed\u53e5\u9000\u51fa\u5faa\u73af\uff0c\u7ed3\u675f\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u9012\u5f52\u8c03\u7528\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u9012\u5f52\u8c03\u7528\u662f\u4e00\u79cd\u51fd\u6570\u81ea\u5df1\u8c03\u7528\u81ea\u5df1\u7684\u7f16\u7a0b\u6280\u672f\uff0c\u53ef\u4ee5\u7528\u6765\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u867d\u7136\u9012\u5f52\u8c03\u7528\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u5f88\u6709\u7528\uff0c\u4f46\u9700\u8981\u5c0f\u5fc3\u4f7f\u7528\uff0c\u907f\u514d\u6808\u6ea2\u51fa\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>    answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>    if answer == &#39;y&#39;:<\/p>\n<p>        main_program()<\/p>\n<p>main_program()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>main_program<\/code>\u51fd\u6570\u5728\u8fd0\u884c\u7ed3\u675f\u540e\uff0c\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u5982\u679c\u7528\u6237\u8f93\u5165\u201cy\u201d\uff0c\u51fd\u6570\u4f1a\u518d\u6b21\u8c03\u7528\u81ea\u5df1\uff0c\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u91cd\u542fPython\u89e3\u91ca\u5668<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u9ad8\u7ea7\u5e94\u7528\u573a\u666f\u4e0b\uff0c\u9700\u8981\u5b8c\u5168\u91cd\u542fPython\u89e3\u91ca\u5668\u6765\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u53ef\u4ee5\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u4e2d\u7684<code>execv<\/code>\u51fd\u6570\u5b9e\u73b0\u8fd9\u4e00\u70b9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import sys<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>    answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>    if answer == &#39;y&#39;:<\/p>\n<p>        python = sys.executable<\/p>\n<p>        os.execl(python, python, *sys.argv)<\/p>\n<p>main_program()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u5f53\u7528\u6237\u9009\u62e9\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u65f6\uff0c\u4f7f\u7528<code>os.execl<\/code>\u51fd\u6570\u91cd\u65b0\u542f\u52a8\u5f53\u524d\u7684Python\u89e3\u91ca\u5668\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u5916\u90e8\u811a\u672c\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u5916\u90e8\u811a\u672c\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u53cd\u590d\u8fd0\u884c\u591a\u4e2a\u4e0d\u540c\u7a0b\u5e8f\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># run_program.py<\/p>\n<p>import subprocess<\/p>\n<p>while True:<\/p>\n<p>    subprocess.run([&quot;python&quot;, &quot;main_program.py&quot;])<\/p>\n<p>    answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>    if answer != &#39;y&#39;:<\/p>\n<p>        break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\"># main_program.py<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>main_program()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>run_program.py<\/code>\u811a\u672c\u7528\u4e8e\u63a7\u5236<code>main_program.py<\/code>\u7684\u8fd0\u884c\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u7c7b\u548c\u65b9\u6cd5\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u7c7b\u548c\u65b9\u6cd5\u53ef\u4ee5\u66f4\u597d\u5730\u7ec4\u7ec7\u4ee3\u7801\uff0c\u5e76\u4e14\u63d0\u4f9b\u4e86\u4e00\u79cd\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u6765\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class ProgramRunner:<\/p>\n<p>    def __init__(self):<\/p>\n<p>        pass<\/p>\n<p>    def main_program(self):<\/p>\n<p>        # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>        print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>        # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>    def run(self):<\/p>\n<p>        while True:<\/p>\n<p>            self.main_program()<\/p>\n<p>            answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>            if answer != &#39;y&#39;:<\/p>\n<p>                break<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    runner = ProgramRunner()<\/p>\n<p>    runner.run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>ProgramRunner<\/code>\u7c7b\u5305\u542b\u4e86\u4e3b\u7a0b\u5e8f\u903b\u8f91\u548c\u63a7\u5236\u91cd\u65b0\u8fd0\u884c\u7684\u903b\u8f91\u3002\u901a\u8fc7\u5b9e\u4f8b\u5316\u8fd9\u4e2a\u7c7b\u5e76\u8c03\u7528<code>run<\/code>\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5b9e\u73b0\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528\u88c5\u9970\u5668\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u88c5\u9970\u5668\u662f\u4e00\u79cd\u9ad8\u7ea7\u7684Python\u7279\u6027\uff0c\u53ef\u4ee5\u7528\u6765\u4fee\u6539\u51fd\u6570\u7684\u884c\u4e3a\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u88c5\u9970\u5668\u6765\u5b9e\u73b0\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u7684\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def rerun_decorator(func):<\/p>\n<p>    def wrapper():<\/p>\n<p>        while True:<\/p>\n<p>            func()<\/p>\n<p>            answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>            if answer != &#39;y&#39;:<\/p>\n<p>                break<\/p>\n<p>    return wrapper<\/p>\n<p>@rerun_decorator<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>main_program()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>rerun_decorator<\/code>\u88c5\u9970\u5668\u7528\u4e8e\u5305\u88c5\u4e3b\u7a0b\u5e8f\u51fd\u6570<code>main_program<\/code>\uff0c\u4f7f\u5176\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528\u7ebf\u7a0b\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u590d\u6742\u7684\u573a\u666f\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u7ebf\u7a0b\u6765\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u867d\u7136\u8fd9\u79cd\u65b9\u6cd5\u66f4\u4e3a\u590d\u6742\uff0c\u4f46\u5728\u5904\u7406\u5e76\u53d1\u4efb\u52a1\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import threading<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>def run_program():<\/p>\n<p>    while True:<\/p>\n<p>        main_program()<\/p>\n<p>        answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>        if answer != &#39;y&#39;:<\/p>\n<p>            break<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    thread = threading.Thread(target=run_program)<\/p>\n<p>    thread.start()<\/p>\n<p>    thread.join()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528\u7ebf\u7a0b\u6765\u8fd0\u884c\u4e3b\u7a0b\u5e8f\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u4f7f\u7528\u534f\u7a0b\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u534f\u7a0b\u662f\u4e00\u79cd\u6bd4\u7ebf\u7a0b\u66f4\u52a0\u8f7b\u91cf\u7ea7\u7684\u5e76\u53d1\u7f16\u7a0b\u65b9\u5f0f\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>asyncio<\/code>\u6a21\u5757\u6765\u5b9e\u73b0\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import asyncio<\/p>\n<p>async def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>async def run_program():<\/p>\n<p>    while True:<\/p>\n<p>        await main_program()<\/p>\n<p>        answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>        if answer != &#39;y&#39;:<\/p>\n<p>            break<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    asyncio.run(run_program())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528\u534f\u7a0b\u6765\u8fd0\u884c\u4e3b\u7a0b\u5e8f\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u4f7f\u7528\u4fe1\u53f7\u5904\u7406\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u9700\u8981\u5904\u7406\u5916\u90e8\u4e2d\u65ad\u4fe1\u53f7\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>signal<\/code>\u6a21\u5757\u6765\u5b9e\u73b0\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import signal<\/p>\n<p>import sys<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>def signal_handler(sig, frame):<\/p>\n<p>    answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>    if answer == &#39;y&#39;:<\/p>\n<p>        main_program()<\/p>\n<p>    else:<\/p>\n<p>        sys.exit(0)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    signal.signal(signal.SIGINT, signal_handler)<\/p>\n<p>    main_program()<\/p>\n<p>    signal.pause()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528\u4fe1\u53f7\u5904\u7406\u6765\u6355\u6349\u4e2d\u65ad\u4fe1\u53f7\uff0c\u5e76\u5728\u6355\u6349\u5230\u4fe1\u53f7\u65f6\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u3001\u4f7f\u7528\u8c03\u5ea6\u5668\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528\u4efb\u52a1\u8c03\u5ea6\u5668\uff0c\u4f8b\u5982<code>schedule<\/code>\u5e93\u6765\u5b9a\u65f6\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5b9a\u65f6\u8fd0\u884c\u7684\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import schedule<\/p>\n<p>import time<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>def job():<\/p>\n<p>    main_program()<\/p>\n<p>    answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>    if answer != &#39;y&#39;:<\/p>\n<p>        schedule.clear()<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    schedule.every().day.at(&quot;10:00&quot;).do(job)<\/p>\n<p>    while True:<\/p>\n<p>        schedule.run_pending()<\/p>\n<p>        time.sleep(1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528<code>schedule<\/code>\u5e93\u6765\u5b9a\u65f6\u8fd0\u884c\u4e3b\u7a0b\u5e8f\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u4e00\u3001\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u548c\u8bfb\u53d6\u73af\u5883\u53d8\u91cf\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5728\u4e0d\u540c\u8fd0\u884c\u73af\u5883\u4e2d\u63a7\u5236\u7a0b\u5e8f\u884c\u4e3a\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    while True:<\/p>\n<p>        main_program()<\/p>\n<p>        answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>        if answer == &#39;y&#39;:<\/p>\n<p>            os.environ[&quot;RERUN_PROGRAM&quot;] = &quot;1&quot;<\/p>\n<p>        else:<\/p>\n<p>            os.environ[&quot;RERUN_PROGRAM&quot;] = &quot;0&quot;<\/p>\n<p>            break<\/p>\n<p>        if os.environ.get(&quot;RERUN_PROGRAM&quot;) == &quot;0&quot;:<\/p>\n<p>            break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u4e8c\u3001\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u8bfb\u53d6\u548c\u5199\u5165\u914d\u7f6e\u6587\u4ef6\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u6301\u4e45\u5316\u914d\u7f6e\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import configparser<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    config = configparser.ConfigParser()<\/p>\n<p>    config.read(&quot;config.ini&quot;)<\/p>\n<p>    while True:<\/p>\n<p>        main_program()<\/p>\n<p>        answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>        if answer == &#39;y&#39;:<\/p>\n<p>            config[&quot;DEFAULT&quot;][&quot;RERUN_PROGRAM&quot;] = &quot;1&quot;<\/p>\n<p>        else:<\/p>\n<p>            config[&quot;DEFAULT&quot;][&quot;RERUN_PROGRAM&quot;] = &quot;0&quot;<\/p>\n<p>            with open(&quot;config.ini&quot;, &quot;w&quot;) as configfile:<\/p>\n<p>                config.write(configfile)<\/p>\n<p>            break<\/p>\n<p>        if config[&quot;DEFAULT&quot;].get(&quot;RERUN_PROGRAM&quot;) == &quot;0&quot;:<\/p>\n<p>            break<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u4e09\u3001\u4f7f\u7528\u6570\u636e\u5e93\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u8bfb\u53d6\u548c\u5199\u5165\u6570\u636e\u5e93\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5728\u591a\u4e2a\u7a0b\u5e8f\u5b9e\u4f8b\u4e4b\u95f4\u5171\u4eab\u72b6\u6001\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sqlite3<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    conn = sqlite3.connect(&quot;program.db&quot;)<\/p>\n<p>    cursor = conn.cursor()<\/p>\n<p>    cursor.execute(&quot;CREATE TABLE IF NOT EXISTS settings (key TEXT PRIMARY KEY, value TEXT)&quot;)<\/p>\n<p>    cursor.execute(&quot;INSERT OR REPLACE INTO settings (key, value) VALUES (&#39;RERUN_PROGRAM&#39;, &#39;1&#39;)&quot;)<\/p>\n<p>    conn.commit()<\/p>\n<p>    while True:<\/p>\n<p>        main_program()<\/p>\n<p>        answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>        if answer == &#39;y&#39;:<\/p>\n<p>            cursor.execute(&quot;UPDATE settings SET value = &#39;1&#39; WHERE key = &#39;RERUN_PROGRAM&#39;&quot;)<\/p>\n<p>        else:<\/p>\n<p>            cursor.execute(&quot;UPDATE settings SET value = &#39;0&#39; WHERE key = &#39;RERUN_PROGRAM&#39;&quot;)<\/p>\n<p>            conn.commit()<\/p>\n<p>            break<\/p>\n<p>        if cursor.execute(&quot;SELECT value FROM settings WHERE key = &#39;RERUN_PROGRAM&#39;&quot;).fetchone()[0] == &#39;0&#39;:<\/p>\n<p>            break<\/p>\n<p>    conn.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528SQLite\u6570\u636e\u5e93\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u56db\u3001\u4f7f\u7528\u6d88\u606f\u961f\u5217\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7\u6d88\u606f\u961f\u5217\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u534f\u8c03\u591a\u4e2a\u7a0b\u5e8f\u5b9e\u4f8b\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pika<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>def on_message(channel, method_frame, header_frame, body):<\/p>\n<p>    if body.decode() == &#39;rerun&#39;:<\/p>\n<p>        main_program()<\/p>\n<p>        answer = input(&quot;\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\uff1f(y\/n): &quot;).strip().lower()<\/p>\n<p>        if answer == &#39;y&#39;:<\/p>\n<p>            channel.basic_publish(exchange=&#39;&#39;, routing_key=&#39;program_queue&#39;, body=&#39;rerun&#39;)<\/p>\n<p>        else:<\/p>\n<p>            channel.basic_publish(exchange=&#39;&#39;, routing_key=&#39;program_queue&#39;, body=&#39;stop&#39;)<\/p>\n<p>            channel.stop_consuming()<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    connection = pika.BlockingConnection(pika.ConnectionParameters(&#39;localhost&#39;))<\/p>\n<p>    channel = connection.channel()<\/p>\n<p>    channel.queue_declare(queue=&#39;program_queue&#39;)<\/p>\n<p>    channel.basic_consume(queue=&#39;program_queue&#39;, on_message_callback=on_message, auto_ack=True)<\/p>\n<p>    channel.basic_publish(exchange=&#39;&#39;, routing_key=&#39;program_queue&#39;, body=&#39;rerun&#39;)<\/p>\n<p>    channel.start_consuming()<\/p>\n<p>    connection.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528RabbitMQ\u6d88\u606f\u961f\u5217\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u8be2\u95ee\u7528\u6237\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u4e94\u3001\u4f7f\u7528REST API\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u901a\u8fc7REST API\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u901a\u8fc7\u7f51\u7edc\u63a5\u53e3\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from flask import Flask, request, jsonify<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>def main_program():<\/p>\n<p>    # \u4e3b\u7a0b\u5e8f\u7684\u4ee3\u7801<\/p>\n<p>    print(&quot;\u8fd0\u884c\u4e3b\u7a0b\u5e8f...&quot;)<\/p>\n<p>    # \u4f8b\u5982\uff1a\u8ba1\u7b97\u3001\u5904\u7406\u6570\u636e\u7b49<\/p>\n<p>@app.route(&#39;\/run&#39;, methods=[&#39;POST&#39;])<\/p>\n<p>def run_program():<\/p>\n<p>    main_program()<\/p>\n<p>    data = request.get_json()<\/p>\n<p>    if data.get(&quot;rerun&quot;) == &#39;y&#39;:<\/p>\n<p>        return jsonify({&quot;message&quot;: &quot;Program will rerun&quot;}), 200<\/p>\n<p>    else:<\/p>\n<p>        return jsonify({&quot;message&quot;: &quot;Program will stop&quot;}), 200<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    app.run(port=5000)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u4f7f\u7528Flask\u6846\u67b6\u63d0\u4f9b\u4e00\u4e2aREST API\u63a5\u53e3\u6765\u63a7\u5236\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\uff0c\u5e76\u5728\u6bcf\u6b21\u8fd0\u884c\u7ed3\u675f\u540e\u901a\u8fc7API\u8bf7\u6c42\u63a7\u5236\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002<\/p>\n<\/p>\n<p><p>\u4ee5\u4e0a\u51e0\u79cd\u65b9\u6cd5\u5c55\u793a\u4e86\u4e0d\u540c\u573a\u666f\u4e0b\u5982\u4f55\u91cd\u65b0\u8fd0\u884cPython\u7a0b\u5e8f\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u5b9e\u73b0\u7a0b\u5e8f\u7684\u91cd\u65b0\u8fd0\u884c\uff0c\u5e76\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u6269\u5c55\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u91cd\u65b0\u542f\u52a8\u7a0b\u5e8f\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>os<\/code>\u6a21\u5757\u4e2d\u7684<code>exec()<\/code>\u51fd\u6570\u6765\u91cd\u65b0\u8fd0\u884c\u5f53\u524d\u811a\u672c\u3002\u60a8\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u6761\u4ef6\u6765\u51b3\u5b9a\u662f\u5426\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u7a0b\u5e8f\u672b\u5c3e\u4f7f\u7528<code>exec(open(__file__).read())<\/code>\u6765\u91cd\u65b0\u6267\u884c\u5f53\u524d\u6587\u4ef6\u7684\u5185\u5bb9\u3002<\/p>\n<p><strong>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u5982\u4f55\u5feb\u901f\u91cd\u542fPython\u7a0b\u5e8f\uff1f<\/strong><br \/>\u5728\u5f00\u53d1\u65f6\uff0c\u60a8\u53ef\u4ee5\u5229\u7528\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u4e2d\u7684\u5feb\u6377\u952e\u6765\u5feb\u901f\u91cd\u542f\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u5728PyCharm\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528Shift + F10\u6765\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u3002\u5176\u4ed6IDE\u4e5f\u6709\u7c7b\u4f3c\u7684\u529f\u80fd\uff0c\u60a8\u53ef\u4ee5\u67e5\u9605\u76f8\u5e94\u7684\u6587\u6863\u4ee5\u83b7\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u5904\u7406\u7a0b\u5e8f\u91cd\u542f\u540e\u7684\u72b6\u6001\uff1f<\/strong><br \/>\u4e3a\u4e86\u5728\u7a0b\u5e8f\u91cd\u542f\u540e\u4fdd\u6301\u72b6\u6001\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6587\u4ef6\u5b58\u50a8\u6216\u6570\u636e\u5e93\u6765\u4fdd\u5b58\u91cd\u8981\u6570\u636e\u3002\u5728\u7a0b\u5e8f\u542f\u52a8\u65f6\uff0c\u8bfb\u53d6\u8fd9\u4e9b\u6570\u636e\u5e76\u6062\u590d\u72b6\u6001\u3002\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u5728\u91cd\u542f\u540e\uff0c\u7a0b\u5e8f\u80fd\u591f\u7ee7\u7eed\u4ece\u4e0a\u6b21\u7ed3\u675f\u7684\u5730\u65b9\u8fd0\u884c\uff0c\u800c\u4e0d\u4e22\u5931\u5173\u952e\u6570\u636e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u91cd\u65b0\u8fd0\u884c\u7a0b\u5e8f\u7684\u65b9\u5f0f\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u9012\u5f52\u51fd\u6570\u3001while\u5faa\u73af\u3001\u91cd\u542fPython\u89e3\u91ca\u5668\u3001\u4f7f\u7528\u5916\u90e8\u811a\u672c\u7b49 [&hellip;]","protected":false},"author":3,"featured_media":1178085,"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\/1178084"}],"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=1178084"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1178084\/revisions"}],"predecessor-version":[{"id":1178090,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1178084\/revisions\/1178090"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1178085"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1178084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1178084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1178084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}