{"id":1011606,"date":"2024-12-27T11:31:25","date_gmt":"2024-12-27T03:31:25","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1011606.html"},"modified":"2024-12-27T11:31:28","modified_gmt":"2024-12-27T03:31:28","slug":"%e5%a6%82%e4%bd%95%e9%87%8d%e5%a4%8d%e6%89%a7%e8%a1%8cpython%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1011606.html","title":{"rendered":"\u5982\u4f55\u91cd\u590d\u6267\u884cpython\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25085657\/e04c03f2-61fb-40e9-b587-ab7c7495279e.webp\" alt=\"\u5982\u4f55\u91cd\u590d\u6267\u884cpython\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>\u8981\u91cd\u590d\u6267\u884cPython\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u3001\u8c03\u5ea6\u5668\u6216\u811a\u672c\u7ba1\u7406\u5de5\u5177\u3002\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5e38\u89c1\u7684\u5305\u62ec\uff1a\u4f7f\u7528while\u5faa\u73af\u3001\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u4efb\u52a1\u8c03\u5ea6\u529f\u80fd\u3001\u4f7f\u7528\u811a\u672c\u5de5\u5177\u7b49\u3002\u4f7f\u7528while\u5faa\u73af\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728Python\u4ee3\u7801\u4e2d\u76f4\u63a5\u8c03\u7528\u81ea\u8eab\u6765\u5b9e\u73b0\u6587\u4ef6\u7684\u91cd\u590d\u6267\u884c\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u8fd9\u79cd\u65b9\u6cd5\u4e2d\uff0c\u4f60\u9700\u8981\u5728Python\u811a\u672c\u4e2d\u5d4c\u5165\u4e00\u4e2a\u5faa\u73af\uff0c\u6bd4\u5982while\u5faa\u73af\uff0c\u4f7f\u5f97\u811a\u672c\u5728\u6ee1\u8db3\u4e00\u5b9a\u6761\u4ef6\u65f6\u91cd\u65b0\u8c03\u7528\u81ea\u8eab\u3002\u8fd9\u6837\u53ef\u4ee5\u5b9e\u73b0\u811a\u672c\u7684\u91cd\u590d\u6267\u884c\u3002\u4e3a\u4e86\u9632\u6b62\u65e0\u9650\u5faa\u73af\u5bfc\u81f4\u8d44\u6e90\u8017\u5c3d\uff0c\u901a\u5e38\u9700\u8981\u52a0\u5165\u4e00\u4e9b\u63a7\u5236\u673a\u5236\uff0c\u6bd4\u5982\u8ba1\u6570\u5668\u6216\u65f6\u95f4\u5ef6\u8fdf\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u51e0\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\uff0c\u4ee5\u5e2e\u52a9\u4f60\u9009\u62e9\u6700\u5408\u9002\u7684\u65b9\u6848\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528WHILE\u5faa\u73af<\/p>\n<\/p>\n<p><p>\u5728Python\u811a\u672c\u4e2d\uff0c\u4f7f\u7528while\u5faa\u73af\u662f\u5b9e\u73b0\u91cd\u590d\u6267\u884c\u7684\u4e00\u79cd\u7b80\u5355\u65b9\u6cd5\u3002\u901a\u8fc7\u5728\u811a\u672c\u4e2d\u5d4c\u5165\u5faa\u73af\u7ed3\u6784\uff0c\u53ef\u4ee5\u5728\u6ee1\u8db3\u4e00\u5b9a\u6761\u4ef6\u65f6\u91cd\u65b0\u8fd0\u884c\u811a\u672c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u57fa\u672c\u7ed3\u6784<\/strong>\uff1a\u5728Python\u811a\u672c\u4e2d\uff0c\u4f7f\u7528while\u5faa\u73af\u53ef\u4ee5\u6301\u7eed\u6267\u884c\u67d0\u6bb5\u4ee3\u7801\u3002\u901a\u8fc7\u8bbe\u7f6e\u6761\u4ef6\uff0c\u53ef\u4ee5\u63a7\u5236\u5faa\u73af\u7684\u6267\u884c\u6b21\u6570\u6216\u4e2d\u6b62\u6761\u4ef6\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>def m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n():<\/p>\n<p>    print(&quot;\u6267\u884c\u4efb\u52a1&quot;)<\/p>\n<p>    # \u5728\u8fd9\u91cc\u6267\u884c\u4f60\u7684\u4e3b\u8981\u4efb\u52a1<\/p>\n<p>    time.sleep(5)  # \u5ef6\u8fdf5\u79d2<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    while True:<\/p>\n<p>        main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u51fd\u6570<code>main()<\/code>\u4ee3\u8868\u4f60\u9700\u8981\u6267\u884c\u7684\u4efb\u52a1\uff0c\u800c<code>while True<\/code>\u5faa\u73af\u5219\u786e\u4fdd<code>main()<\/code>\u51fd\u6570\u4e0d\u65ad\u91cd\u590d\u6267\u884c\u3002<code>time.sleep(5)<\/code>\u7528\u4e8e\u5728\u6bcf\u6b21\u6267\u884c\u540e\u6682\u505c5\u79d2\uff0c\u4ee5\u907f\u514d\u8d44\u6e90\u8fc7\u5ea6\u6d88\u8017\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u63a7\u5236\u6267\u884c\u6b21\u6570<\/strong>\uff1a\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u8ba1\u6570\u5668\u6765\u63a7\u5236\u5faa\u73af\u7684\u6267\u884c\u6b21\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>def main():<\/p>\n<p>    print(&quot;\u6267\u884c\u4efb\u52a1&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    count = 0<\/p>\n<p>    max_count = 10  # \u6700\u5927\u6267\u884c\u6b21\u6570<\/p>\n<p>    while count &lt; max_count:<\/p>\n<p>        main()<\/p>\n<p>        count += 1<\/p>\n<p>        time.sleep(5)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u811a\u672c\u6700\u591a\u6267\u884c10\u6b21\uff0c\u7136\u540e\u9000\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528SCHEDULER\u6a21\u5757<\/p>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86<code>scheduler<\/code>\u6a21\u5757\uff0c\u53ef\u4ee5\u7528\u4e8e\u5b9a\u65f6\u6267\u884c\u4efb\u52a1\u3002\u8fd9\u4e2a\u6a21\u5757\u9002\u7528\u4e8e\u9700\u8981\u5728\u7279\u5b9a\u65f6\u95f4\u95f4\u9694\u91cd\u590d\u6267\u884c\u4efb\u52a1\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5\u6a21\u5757<\/strong>\uff1a\u5982\u679c\u4f60\u4f7f\u7528\u7684\u662f\u6807\u51c6\u5e93\u7684<code>scheduler<\/code>\u6a21\u5757\uff0c\u5219\u65e0\u9700\u989d\u5916\u5b89\u88c5\u3002\u5426\u5219\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u7b2c\u4e09\u65b9\u8c03\u5ea6\u6a21\u5757\uff0c\u5982<code>apscheduler<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528scheduler\u6a21\u5757<\/strong>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>import sched<\/p>\n<p>s = sched.scheduler(time.time, time.sleep)<\/p>\n<p>def main():<\/p>\n<p>    print(&quot;\u6267\u884c\u4efb\u52a1&quot;)<\/p>\n<p>def schedule_task(scheduler, interval, action, actionargs=()):<\/p>\n<p>    scheduler.enter(interval, 1, schedule_task, (scheduler, interval, action, actionargs))<\/p>\n<p>    action(*actionargs)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    interval = 5  # \u6267\u884c\u95f4\u9694\uff0c\u5355\u4f4d\u4e3a\u79d2<\/p>\n<p>    s.enter(0, 1, schedule_task, (s, interval, main))<\/p>\n<p>    s.run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>scheduler<\/code>\u6a21\u5757\u7528\u4e8e\u6bcf\u96945\u79d2\u91cd\u590d\u6267\u884c<code>main()<\/code>\u51fd\u6570\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u4efb\u52a1\u8c03\u5ea6\u529f\u80fd<\/p>\n<\/p>\n<p><p>\u64cd\u4f5c\u7cfb\u7edf\u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u5f0f\u6765\u5b9a\u65f6\u6267\u884c\u4efb\u52a1\uff0c\u6bd4\u5982Windows\u7684\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u548cLinux\u7684cron\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Windows\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f<\/strong>\uff1a\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u8ba1\u5212\u4efb\u52a1\u6765\u91cd\u590d\u6267\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u3002<\/li>\n<li>\u521b\u5efa\u65b0\u4efb\u52a1\uff0c\u8bbe\u7f6e\u89e6\u53d1\u5668\u4e3a\u5b9a\u65f6\u91cd\u590d\u3002<\/li>\n<li>\u8bbe\u7f6e\u64cd\u4f5c\u4e3a\u6267\u884cPython\u89e3\u91ca\u5668\u5e76\u4f20\u5165\u811a\u672c\u8def\u5f84\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>Linux\u7684cron<\/strong>\uff1aLinux\u7cfb\u7edf\u4f7f\u7528cron\u6765\u5b9a\u65f6\u6267\u884c\u4efb\u52a1\u3002<\/p>\n<\/p>\n<ul>\n<li>\u6253\u5f00\u7ec8\u7aef\uff0c\u8f93\u5165<code>crontab -e<\/code>\u3002<\/li>\n<li>\u6dfb\u52a0\u65b0\u4efb\u52a1\uff0c\u4f8b\u5982\u6bcf\u5c0f\u65f6\u6267\u884c\u4e00\u6b21\uff1a<code>0 * * * * \/usr\/bin\/python3 \/path\/to\/your_script.py<\/code>\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u4f7f\u7528\u811a\u672c\u7ba1\u7406\u5de5\u5177<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u4e00\u4e9b\u811a\u672c\u7ba1\u7406\u5de5\u5177\u53ef\u4ee5\u65b9\u4fbf\u5730\u7ba1\u7406\u548c\u8c03\u5ea6\u811a\u672c\u7684\u6267\u884c\u3002\u5e38\u7528\u7684\u5de5\u5177\u5305\u62ecSupervisor\u3001PM2\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>Supervisor<\/strong>\uff1a\u7528\u4e8e\u7ba1\u7406\u548c\u76d1\u63a7\u8fdb\u7a0b\uff0c\u53ef\u4ee5\u5728\u8fdb\u7a0b\u610f\u5916\u7ec8\u6b62\u65f6\u81ea\u52a8\u91cd\u542f\u3002<\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5\uff1a<code>sudo apt-get install supervisor<\/code><\/li>\n<li>\u914d\u7f6e\uff1a\u5728<code>\/etc\/supervisor\/conf.d\/<\/code>\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u5b9a\u8981\u6267\u884c\u7684\u811a\u672c\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>PM2<\/strong>\uff1a\u4e3b\u8981\u7528\u4e8eNode.js\u5e94\u7528\uff0c\u4f46\u540c\u6837\u652f\u6301Python\u811a\u672c\u3002<\/p>\n<\/p>\n<ul>\n<li>\u5b89\u88c5\uff1a<code>npm install pm2 -g<\/code><\/li>\n<li>\u4f7f\u7528\uff1a<code>pm2 start your_script.py --interpreter=python3<\/code><\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u811a\u672c\u81ea\u52a8\u91cd\u542f\u6280\u672f<\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u811a\u672c\u53ef\u80fd\u4f1a\u7531\u4e8e\u5f02\u5e38\u800c\u9000\u51fa\u3002\u4e3a\u4e86\u786e\u4fdd\u811a\u672c\u7684\u8fde\u7eed\u8fd0\u884c\uff0c\u53ef\u4ee5\u91c7\u7528\u81ea\u52a8\u91cd\u542f\u6280\u672f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528try-except\u5757<\/strong>\uff1a\u5728\u811a\u672c\u4e2d\u6355\u83b7\u5f02\u5e38\u5e76\u5728\u5f02\u5e38\u53d1\u751f\u65f6\u91cd\u65b0\u542f\u52a8\u811a\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import time<\/p>\n<p>def main():<\/p>\n<p>    try:<\/p>\n<p>        print(&quot;\u6267\u884c\u4efb\u52a1&quot;)<\/p>\n<p>        # \u5728\u8fd9\u91cc\u6267\u884c\u4f60\u7684\u4e3b\u8981\u4efb\u52a1<\/p>\n<p>    except Exception as e:<\/p>\n<p>        print(f&quot;\u53d1\u751f\u9519\u8bef: {e}&quot;)<\/p>\n<p>        time.sleep(5)  # \u5ef6\u8fdf5\u79d2\u540e\u91cd\u8bd5<\/p>\n<p>        main()<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    while True:<\/p>\n<p>        main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u4efb\u4f55\u672a\u6355\u83b7\u7684\u5f02\u5e38\u90fd\u4f1a\u5bfc\u81f4\u811a\u672c\u57285\u79d2\u540e\u91cd\u65b0\u542f\u52a8\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528\u5916\u90e8\u811a\u672c\u76d1\u63a7<\/strong>\uff1a\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u5916\u90e8\u811a\u672c\u6765\u76d1\u63a7\u76ee\u6807\u811a\u672c\u7684\u8fd0\u884c\u72b6\u6001\uff0c\u5e76\u5728\u5176\u9000\u51fa\u65f6\u81ea\u52a8\u91cd\u542f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">#!\/bin\/bash<\/p>\n<p>while true; do<\/p>\n<p>    python3 \/path\/to\/your_script.py<\/p>\n<p>    echo &quot;\u811a\u672c\u5df2\u9000\u51fa\uff0c5\u79d2\u540e\u91cd\u65b0\u542f\u52a8...&quot;<\/p>\n<p>    sleep 5<\/p>\n<p>done<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5c06\u8fd9\u4e2aBash\u811a\u672c\u4fdd\u5b58\u4e3a.sh\u6587\u4ef6\uff0c\u5e76\u901a\u8fc7<code>bash script_name.sh<\/code>\u6765\u8fd0\u884c\uff0c\u4ece\u800c\u5b9e\u73b0\u76ee\u6807\u811a\u672c\u7684\u81ea\u52a8\u91cd\u542f\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u6c42\u9009\u62e9\u9002\u5408\u7684\u65b9\u6848\u6765\u5b9e\u73b0Python\u6587\u4ef6\u7684\u91cd\u590d\u6267\u884c\u3002\u8fd9\u4e0d\u4ec5\u63d0\u5347\u4e86\u811a\u672c\u7684\u7075\u6d3b\u6027\uff0c\u8fd8\u589e\u5f3a\u4e86\u4efb\u52a1\u7684\u53ef\u9760\u6027\u548c\u7a33\u5b9a\u6027\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u7ed3\u5408\u591a\u79cd\u65b9\u6cd5\u4ee5\u5b9e\u73b0\u6700\u4f73\u6548\u679c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5b9e\u73b0\u6587\u4ef6\u7684\u91cd\u590d\u6267\u884c\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u7ed3\u6784\u6765\u5b9e\u73b0\u5bf9\u67d0\u4e2a\u6587\u4ef6\u7684\u91cd\u590d\u6267\u884c\u3002\u901a\u8fc7<code>while<\/code>\u6216<code>for<\/code>\u5faa\u73af\uff0c\u60a8\u53ef\u4ee5\u8bbe\u7f6e\u6761\u4ef6\u6765\u63a7\u5236\u6267\u884c\u6b21\u6570\uff0c\u6216\u8005\u8ba9\u7a0b\u5e8f\u5728\u7279\u5b9a\u6761\u4ef6\u6ee1\u8db3\u65f6\u7ee7\u7eed\u6267\u884c\u3002\u53ef\u4ee5\u4f7f\u7528<code>exec()<\/code>\u51fd\u6570\u6267\u884c\u6587\u4ef6\u4e2d\u7684\u4ee3\u7801\uff0c\u6216\u8005\u901a\u8fc7<code>subprocess<\/code>\u6a21\u5757\u8fd0\u884c\u53e6\u4e00\u4e2aPython\u811a\u672c\u3002<\/p>\n<p><strong>\u5728Windows\u548cLinux\u7cfb\u7edf\u4e2d\u5982\u4f55\u91cd\u590d\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u7684<code>python your_script.py<\/code>\u547d\u4ee4\u7ed3\u5408\u5faa\u73af\u8bed\u53e5\u6765\u5b9e\u73b0\u91cd\u590d\u8fd0\u884c\u3002Linux\u7528\u6237\u5219\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528\u7c7b\u4f3c\u7684\u547d\u4ee4\u3002\u60a8\u4e5f\u53ef\u4ee5\u5c06\u8fd9\u4e9b\u547d\u4ee4\u5199\u5165\u4e00\u4e2a\u6279\u5904\u7406\u6587\u4ef6\u6216Shell\u811a\u672c\u4e2d\uff0c\u4ee5\u4fbf\u4e8e\u591a\u6b21\u6267\u884c\u3002<\/p>\n<p><strong>\u5982\u4f55\u63a7\u5236Python\u811a\u672c\u7684\u6267\u884c\u9891\u7387\u4ee5\u907f\u514d\u7cfb\u7edf\u8d1f\u62c5\uff1f<\/strong><br \/>\u5728\u91cd\u590d\u6267\u884cPython\u6587\u4ef6\u65f6\uff0c\u5408\u7406\u63a7\u5236\u6267\u884c\u9891\u7387\u5341\u5206\u91cd\u8981\u3002\u53ef\u4ee5\u4f7f\u7528<code>time.sleep(seconds)<\/code>\u51fd\u6570\u6765\u8bbe\u7f6e\u6bcf\u6b21\u6267\u884c\u4e4b\u95f4\u7684\u95f4\u9694\u65f6\u95f4\uff0c\u786e\u4fdd\u7cfb\u7edf\u8d44\u6e90\u5f97\u5230\u5408\u7406\u5229\u7528\uff0c\u907f\u514d\u56e0\u8fc7\u4e8e\u9891\u7e41\u7684\u6267\u884c\u800c\u9020\u6210\u6027\u80fd\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728\u91cd\u590d\u6267\u884c\u65f6\u4f20\u9012\u53c2\u6570\u7ed9Python\u6587\u4ef6\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u5728\u6267\u884cPython\u6587\u4ef6\u65f6\u901a\u8fc7\u547d\u4ee4\u884c\u53c2\u6570\u4f20\u9012\u503c\uff0c\u5229\u7528<code>sys.argv<\/code>\u6765\u63a5\u6536\u8fd9\u4e9b\u53c2\u6570\u3002\u5728\u811a\u672c\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6761\u4ef6\u5224\u65ad\u6765\u5904\u7406\u4e0d\u540c\u7684\u8f93\u5165\uff0c\u4ece\u800c\u5b9e\u73b0\u7075\u6d3b\u7684\u529f\u80fd\u548c\u5904\u7406\u903b\u8f91\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u91cd\u590d\u6267\u884cPython\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5faa\u73af\u3001\u8c03\u5ea6\u5668\u6216\u811a\u672c\u7ba1\u7406\u5de5\u5177\u3002\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5e38\u89c1\u7684\u5305\u62ec\uff1a\u4f7f\u7528while\u5faa\u73af\u3001\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":1011615,"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\/1011606"}],"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=1011606"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1011606\/revisions"}],"predecessor-version":[{"id":1011618,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1011606\/revisions\/1011618"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1011615"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1011606"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1011606"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1011606"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}