{"id":994946,"date":"2024-12-27T08:59:46","date_gmt":"2024-12-27T00:59:46","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/994946.html"},"modified":"2024-12-27T08:59:49","modified_gmt":"2024-12-27T00:59:49","slug":"%e5%a6%82%e4%bd%95%e9%80%9a%e8%bf%87php%e8%b0%83%e7%94%a8python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/994946.html","title":{"rendered":"\u5982\u4f55\u901a\u8fc7php\u8c03\u7528python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25071730\/d40d5d74-a34c-4638-a0df-42ebedd2923f.webp\" alt=\"\u5982\u4f55\u901a\u8fc7php\u8c03\u7528python\" \/><\/p>\n<p><p> <strong>\u901a\u8fc7PHP\u8c03\u7528Python\u7684\u4e3b\u8981\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528shell\u547d\u4ee4\u6267\u884cPython\u811a\u672c\u3001\u901a\u8fc7HTTP\u8bf7\u6c42\u8c03\u7528Python\u670d\u52a1\u3001\u4f7f\u7528\u6d88\u606f\u961f\u5217\u8fdb\u884c\u5f02\u6b65\u901a\u4fe1\u3002<\/strong>\u5728\u8fd9\u4e09\u79cd\u65b9\u6cd5\u4e2d\uff0c<strong>\u4f7f\u7528shell\u547d\u4ee4\u6267\u884cPython\u811a\u672c<\/strong>\u662f\u6700\u5e38\u89c1\u4e14\u7b80\u5355\u7684\u65b9\u5f0f\u3002\u5b83\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7PHP\u7684<code>exec()<\/code>\u51fd\u6570\u6216<code>shell_exec()<\/code>\u51fd\u6570\u6765\u6267\u884cPython\u811a\u672c\u3002\u4e0b\u9762\uff0c\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u8fd9\u79cd\u65b9\u6cd5\u7684\u5b9e\u73b0\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528shell\u547d\u4ee4\u6267\u884cPython\u811a\u672c\u7684\u6838\u5fc3\u5728\u4e8e\uff0cPHP\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8c03\u7528Python\u89e3\u91ca\u5668\u6765\u8fd0\u884cPython\u811a\u672c\u3002\u9996\u5148\uff0c\u9700\u8981\u786e\u4fdd\u670d\u52a1\u5668\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\uff0c\u5e76\u4e14\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8bbf\u95ee\u3002\u7136\u540e\uff0c\u5728PHP\u4ee3\u7801\u4e2d\u4f7f\u7528<code>exec()<\/code>\u6216<code>shell_exec()<\/code>\u51fd\u6570\u6765\u8fd0\u884cPython\u811a\u672c\uff0c\u5e76\u83b7\u53d6\u8f93\u51fa\u7ed3\u679c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u7b80\u5355\u7684\u4efb\u52a1\uff0c\u4f46\u5982\u679c\u9700\u8981\u5904\u7406\u590d\u6742\u7684\u4e1a\u52a1\u903b\u8f91\u6216\u5927\u89c4\u6a21\u7684\u6570\u636e\u4ea4\u6362\uff0c\u5efa\u8bae\u8003\u8651\u4f7f\u7528HTTP\u8bf7\u6c42\u6216\u6d88\u606f\u961f\u5217\u3002<\/p>\n<\/p>\n<hr>\n<p><h3>\u4e00\u3001\u4f7f\u7528shell\u547d\u4ee4\u6267\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528PHP\u7684<code>exec()<\/code>\u6216<code>shell_exec()<\/code>\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u8c03\u7528Python\u811a\u672c\u3002\u4ee5\u4e0b\u662f\u5177\u4f53\u6b65\u9aa4\uff1a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u786e\u4fdd\u73af\u5883\u914d\u7f6e\u6b63\u786e<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u670d\u52a1\u5668\u4e0a\u5b89\u88c5\u4e86Python\uff0c\u5e76\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u4f7f\u7528\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u68c0\u67e5Python\u7248\u672c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7f16\u5199Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python\u811a\u672c\uff0c\u6bd4\u5982<code>hello.py<\/code>\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># hello.py<\/p>\n<p>import sys<\/p>\n<p>def m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n():<\/p>\n<p>    print(&quot;Hello from Python!&quot;)<\/p>\n<p>    if len(sys.argv) &gt; 1:<\/p>\n<p>        print(f&quot;Argument: {sys.argv[1]}&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5728PHP\u4e2d\u8c03\u7528Python\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u5728PHP\u4e2d\u4f7f\u7528<code>exec()<\/code>\u6216<code>shell_exec()<\/code>\u51fd\u6570\u8c03\u7528Python\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-php\">&lt;?php<\/p>\n<p>\/\/ PHP code to call Python script<\/p>\n<p>$output = shell_exec(&quot;python3 \/path\/to\/hello.py&quot;);<\/p>\n<p>echo $output;<\/p>\n<p>?&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2aPHP\u4ee3\u7801\u5c06\u6267\u884cPython\u811a\u672c\u5e76\u6253\u5370\u5176\u8f93\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u53c2\u6570\u4f20\u9012<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u4f20\u9012\u53c2\u6570\u7ed9Python\u811a\u672c\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u4e2d\u52a0\u5165\u53c2\u6570\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-php\">&lt;?php<\/p>\n<p>\/\/ PHP code to call Python script with an argument<\/p>\n<p>$arg = &quot;test_argument&quot;;<\/p>\n<p>$output = shell_exec(&quot;python3 \/path\/to\/hello.py &quot; . escapeshellarg($arg));<\/p>\n<p>echo $output;<\/p>\n<p>?&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728Python\u811a\u672c\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7<code>sys.argv<\/code>\u83b7\u53d6\u4f20\u9012\u7684\u53c2\u6570\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u5168\u6027\u548c\u9519\u8bef\u5904\u7406<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528<code>exec()<\/code>\u548c<code>shell_exec()<\/code>\u65f6\uff0c\u6ce8\u610f\u8f93\u5165\u53c2\u6570\u7684\u8f6c\u4e49\uff0c\u4ee5\u9632\u6b62\u547d\u4ee4\u6ce8\u5165\u653b\u51fb\u3002\u4f7f\u7528<code>escapeshellarg()<\/code>\u6216<code>escapeshellcmd()<\/code>\u5bf9\u53c2\u6570\u8fdb\u884c\u8f6c\u4e49\u3002\u6b64\u5916\uff0c\u68c0\u67e5\u8fd4\u56de\u503c\u548c\u8f93\u51fa\uff0c\u5904\u7406\u53ef\u80fd\u7684\u9519\u8bef\u60c5\u51b5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u901a\u8fc7HTTP\u8bf7\u6c42\u8c03\u7528Python\u670d\u52a1<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7HTTP\u8bf7\u6c42\u8c03\u7528Python\u670d\u52a1\u662f\u53e6\u4e00\u79cd\u65b9\u6cd5\uff0c\u9002\u5408\u4e8e\u9700\u8981\u5904\u7406\u590d\u6742\u4e1a\u52a1\u903b\u8f91\u6216\u9700\u8981\u4e0e\u5916\u90e8\u670d\u52a1\u4ea4\u4e92\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efaPython Web\u670d\u52a1<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528Flask\u6216Django\u7b49\u6846\u67b6\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Web\u670d\u52a1\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Flask\u521b\u5efa\u4e00\u4e2a\u670d\u52a1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># app.py<\/p>\n<p>from flask import Flask, request, jsonify<\/p>\n<p>app = Flask(__name__)<\/p>\n<p>@app.route(&#39;\/api&#39;, methods=[&#39;GET&#39;])<\/p>\n<p>def api():<\/p>\n<p>    arg = request.args.get(&#39;arg&#39;, default=&#39;No argument&#39;, type=str)<\/p>\n<p>    return jsonify({&quot;message&quot;: &quot;Hello from Python!&quot;, &quot;argument&quot;: arg})<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    app.run(host=&#39;0.0.0.0&#39;, port=5000)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd0\u884c\u8fd9\u4e2aFlask\u5e94\u7528\uff0c\u4f7f\u5176\u5728\u672c\u5730\u670d\u52a1\u5668\u4e0a\u76d1\u542c\u8bf7\u6c42\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5728PHP\u4e2d\u53d1\u9001HTTP\u8bf7\u6c42<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528PHP\u7684<code>curl<\/code>\u5e93\u6216<code>file_get_contents()<\/code>\u51fd\u6570\u53d1\u9001HTTP\u8bf7\u6c42\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-php\">&lt;?php<\/p>\n<p>\/\/ PHP code to send HTTP request to Python service<\/p>\n<p>$url = &#39;http:\/\/localhost:5000\/api?arg=test_argument&#39;;<\/p>\n<p>$response = file_get_contents($url);<\/p>\n<p>echo $response;<\/p>\n<p>?&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u4f7f\u7528<code>curl<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-php\">&lt;?php<\/p>\n<p>\/\/ PHP code using curl to send HTTP request<\/p>\n<p>$ch = curl_init();<\/p>\n<p>curl_setopt($ch, CURLOPT_URL, &quot;http:\/\/localhost:5000\/api?arg=test_argument&quot;);<\/p>\n<p>curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<\/p>\n<p>$response = curl_exec($ch);<\/p>\n<p>curl_close($ch);<\/p>\n<p>echo $response;<\/p>\n<p>?&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u89e3\u6790\u548c\u5904\u7406\u54cd\u5e94<\/strong><\/p>\n<\/p>\n<p><p>\u6536\u5230Python\u670d\u52a1\u7684\u54cd\u5e94\u540e\uff0c\u89e3\u6790JSON\u683c\u5f0f\u7684\u6570\u636e\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u5904\u7406\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u6d88\u606f\u961f\u5217\u8fdb\u884c\u5f02\u6b65\u901a\u4fe1<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u6d88\u606f\u961f\u5217\u8fdb\u884c\u5f02\u6b65\u901a\u4fe1\u662f\u4e00\u79cd\u9002\u5408\u9ad8\u8d1f\u8f7d\u3001\u5927\u89c4\u6a21\u6570\u636e\u4ea4\u6362\u7684\u573a\u666f\u7684\u65b9\u6cd5\u3002\u5e38\u7528\u7684\u6d88\u606f\u961f\u5217\u6709RabbitMQ\u3001Redis\u3001Kafka\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8bbe\u7f6e\u6d88\u606f\u961f\u5217<\/strong><\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5e76\u914d\u7f6e\u6d88\u606f\u961f\u5217\uff0c\u4f8b\u5982RabbitMQ\u3002\u53ef\u4ee5\u4f7f\u7528\u5b98\u65b9\u6587\u6863\u6216Docker\u955c\u50cf\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Python\u811a\u672c\u76d1\u542c\u961f\u5217<\/strong><\/p>\n<\/p>\n<p><p>\u7f16\u5199Python\u811a\u672c\u76d1\u542c\u961f\u5217\uff0c\u5e76\u5904\u7406\u6d88\u606f\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>pika<\/code>\u5e93\u8fde\u63a5RabbitMQ\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># consumer.py<\/p>\n<p>import pika<\/p>\n<p>def callback(ch, method, properties, body):<\/p>\n<p>    print(f&quot;Received {body}&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;task_queue&#39;)<\/p>\n<p>channel.basic_consume(queue=&#39;task_queue&#39;, on_message_callback=callback, auto_ack=True)<\/p>\n<p>print(&#39;Waiting for messages. To exit press CTRL+C&#39;)<\/p>\n<p>channel.start_consuming()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>PHP\u53d1\u9001\u6d88\u606f\u5230\u961f\u5217<\/strong><\/p>\n<\/p>\n<p><p>\u5728PHP\u4e2d\u4f7f\u7528<code>php-amqplib<\/code>\u5e93\u8fde\u63a5RabbitMQ\uff0c\u5e76\u53d1\u9001\u6d88\u606f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-php\">&lt;?php<\/p>\n<p>require_once __DIR__ . &#39;\/vendor\/autoload.php&#39;;<\/p>\n<p>use PhpAmqpLib\\Connection\\AMQPStreamConnection;<\/p>\n<p>use PhpAmqpLib\\Message\\AMQPMessage;<\/p>\n<p>$connection = new AMQPStreamConnection(&#39;localhost&#39;, 5672, &#39;guest&#39;, &#39;guest&#39;);<\/p>\n<p>$channel = $connection-&gt;channel();<\/p>\n<p>$channel-&gt;queue_declare(&#39;task_queue&#39;, false, false, false, false);<\/p>\n<p>$msg = new AMQPMessage(&#39;Hello from PHP!&#39;);<\/p>\n<p>$channel-&gt;basic_publish($msg, &#39;&#39;, &#39;task_queue&#39;);<\/p>\n<p>echo &quot; [x] Sent &#39;Hello from PHP!&#39;\\n&quot;;<\/p>\n<p>$channel-&gt;close();<\/p>\n<p>$connection-&gt;close();<\/p>\n<p>?&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5904\u7406\u6d88\u606f\u548c\u4e1a\u52a1\u903b\u8f91<\/strong><\/p>\n<\/p>\n<p><p>Python\u811a\u672c\u6536\u5230\u6d88\u606f\u540e\uff0c\u6267\u884c\u76f8\u5e94\u7684\u4e1a\u52a1\u903b\u8f91\uff0c\u5e76\u53ef\u80fd\u5c06\u7ed3\u679c\u53d1\u9001\u56dePHP\u6216\u5b58\u50a8\u5728\u6570\u636e\u5e93\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<hr>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4e09\u79cd\u65b9\u6cd5\uff0cPHP\u53ef\u4ee5\u6709\u6548\u5730\u8c03\u7528Python\u811a\u672c\u6216\u670d\u52a1\uff0c\u6ee1\u8db3\u4e0d\u540c\u7684\u4e1a\u52a1\u9700\u6c42\u3002<strong>\u5728\u9009\u62e9\u5177\u4f53\u65b9\u6cd5\u65f6\uff0c\u9700\u6839\u636e\u5b9e\u9645\u60c5\u51b5\u8003\u8651\u4efb\u52a1\u7684\u590d\u6742\u6027\u3001\u6570\u636e\u91cf\u548c\u6027\u80fd\u8981\u6c42\u3002<\/strong><\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728PHP\u4e2d\u8c03\u7528Python\u811a\u672c\uff1f<\/strong><br \/>\u5728PHP\u4e2d\u8c03\u7528Python\u811a\u672c\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>exec()<\/code>\u3001<code>shell_exec()<\/code>\u6216<code>system()<\/code>\u7b49\u51fd\u6570\u6765\u5b9e\u73b0\u3002\u8fd9\u4e9b\u51fd\u6570\u5141\u8bb8\u4f60\u5728PHP\u4ee3\u7801\u4e2d\u6267\u884cShell\u547d\u4ee4\u3002\u4f60\u9700\u8981\u786e\u4fddPython\u811a\u672c\u5177\u6709\u53ef\u6267\u884c\u6743\u9650\uff0c\u5e76\u5728PHP\u4e2d\u6b63\u786e\u6307\u5b9aPython\u89e3\u91ca\u5668\u7684\u8def\u5f84\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-php\">$output = shell_exec(&quot;python3 \/path\/to\/your_script.py&quot;);\necho $output;\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u6709\u6548\u5730\u5c06Python\u7684\u529f\u80fd\u96c6\u6210\u5230PHP\u5e94\u7528\u7a0b\u5e8f\u4e2d\u3002<\/p>\n<p><strong>\u5728\u8c03\u7528Python\u65f6\u5982\u4f55\u5904\u7406\u53c2\u6570\u4f20\u9012\uff1f<\/strong><br \/>\u5982\u679c\u9700\u8981\u5411Python\u811a\u672c\u4f20\u9012\u53c2\u6570\uff0c\u53ef\u4ee5\u5728\u6267\u884c\u547d\u4ee4\u65f6\u76f4\u63a5\u9644\u52a0\u53c2\u6570\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-php\">$name = &quot;Alice&quot;;\n$output = shell_exec(&quot;python3 \/path\/to\/your_script.py $name&quot;);\n<\/code><\/pre>\n<p>\u5728Python\u811a\u672c\u4e2d\uff0c\u4f7f\u7528<code>sys.argv<\/code>\u6765\u63a5\u6536\u8fd9\u4e9b\u53c2\u6570\u3002\u4f8b\u5982\uff1a  <\/p>\n<pre><code class=\"language-python\">import sys\nname = sys.argv[1]\nprint(f&quot;Hello, {name}&quot;)\n<\/code><\/pre>\n<p>\u786e\u4fdd\u5bf9\u8f93\u5165\u53c2\u6570\u8fdb\u884c\u9002\u5f53\u7684\u9a8c\u8bc1\u548c\u5904\u7406\uff0c\u4ee5\u907f\u514d\u5b89\u5168\u95ee\u9898\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406PHP\u4e0ePython\u4e4b\u95f4\u7684\u6570\u636e\u4ea4\u6362\uff1f<\/strong><br \/>\u5728PHP\u4e0ePython\u4e4b\u95f4\u8fdb\u884c\u6570\u636e\u4ea4\u6362\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7JSON\u683c\u5f0f\u8fdb\u884c\u3002PHP\u53ef\u4ee5\u5c06\u6570\u636e\u7f16\u7801\u4e3aJSON\uff0cPython\u5219\u53ef\u4ee5\u89e3\u6790\u8fd9\u4e9b\u6570\u636e\u3002\u5b9e\u73b0\u793a\u4f8b\u5982\u4e0b\uff1a<br \/>\u5728PHP\u4e2d\uff0c\u4f7f\u7528<code>json_encode()<\/code>\u5c06\u6570\u636e\u8f6c\u6362\u4e3aJSON\u683c\u5f0f\uff1a  <\/p>\n<pre><code class=\"language-php\">$data = [&#39;key&#39; =&gt; &#39;value&#39;];\n$jsonData = json_encode($data);\n$output = shell_exec(&quot;python3 \/path\/to\/your_script.py &#39;$jsonData&#39;&quot;);\n<\/code><\/pre>\n<p>\u5728Python\u4e2d\uff0c\u4f7f\u7528<code>json.loads()<\/code>\u89e3\u6790\u63a5\u6536\u5230\u7684JSON\u6570\u636e\uff1a  <\/p>\n<pre><code class=\"language-python\">import sys\nimport json\n\ndata = json.loads(sys.argv[1])\nprint(data[&#39;key&#39;])  # \u8f93\u51fa: value\n<\/code><\/pre>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u80fd\u6709\u6548\u5730\u5728\u4e24\u4e2a\u8bed\u8a00\u4e4b\u95f4\u4f20\u9012\u590d\u6742\u6570\u636e\u7ed3\u6784\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u901a\u8fc7PHP\u8c03\u7528Python\u7684\u4e3b\u8981\u65b9\u6cd5\u6709\uff1a\u4f7f\u7528shell\u547d\u4ee4\u6267\u884cPython\u811a\u672c\u3001\u901a\u8fc7HTTP\u8bf7\u6c42\u8c03\u7528Pytho [&hellip;]","protected":false},"author":3,"featured_media":994952,"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\/994946"}],"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=994946"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/994946\/revisions"}],"predecessor-version":[{"id":994954,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/994946\/revisions\/994954"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/994952"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=994946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=994946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=994946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}