{"id":1178629,"date":"2025-01-15T18:13:23","date_gmt":"2025-01-15T10:13:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1178629.html"},"modified":"2025-01-15T18:13:27","modified_gmt":"2025-01-15T10:13:27","slug":"python%e5%a6%82%e4%bd%95%e8%87%aa%e5%ae%9a%e4%b9%89%e8%be%93%e5%85%a5-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1178629.html","title":{"rendered":"Python\u5982\u4f55\u81ea\u5b9a\u4e49\u8f93\u5165"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25113230\/5b4e4c16-35b4-4656-af2e-0e3bdcdb8eb0.webp\" alt=\"Python\u5982\u4f55\u81ea\u5b9a\u4e49\u8f93\u5165\" \/><\/p>\n<p><p> \u5728Python\u4e2d\u81ea\u5b9a\u4e49\u8f93\u5165\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4f8b\u5982\u4f7f\u7528 <code>input()<\/code> \u51fd\u6570\u3001 <code>argparse<\/code> \u6a21\u5757\u4ee5\u53ca\u521b\u5efa\u56fe\u5f62\u7528\u6237\u754c\u9762\u7b49\u3002<strong>\u5176\u4e2d\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 <code>input()<\/code> \u51fd\u6570\u3001 <code>argparse<\/code> \u6a21\u5757\u548c\u901a\u8fc7\u6587\u4ef6\u8bfb\u53d6\u8f93\u5165<\/strong>\u3002\u63a5\u4e0b\u6765\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u76f8\u5173\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<\/p>\n<h2><strong>PYTHON\u81ea\u5b9a\u4e49\u8f93\u5165<\/strong><\/h2>\n<p><h2>\u4e00\u3001\u4f7f\u7528 <code>input()<\/code> \u51fd\u6570<\/h2>\n<\/p>\n<p><p><code>input()<\/code> \u51fd\u6570\u662fPython\u4e2d\u6700\u7b80\u5355\u3001\u6700\u5e38\u7528\u7684\u8f93\u5165\u65b9\u6cd5\u3002\u5b83\u7528\u4e8e\u4ece\u6807\u51c6\u8f93\u5165\uff08\u901a\u5e38\u662f\u952e\u76d8\uff09\u83b7\u53d6\u8f93\u5165\u3002\u4ee5\u4e0b\u662f <code>input()<\/code> \u51fd\u6570\u7684\u8be6\u7ec6\u4ecb\u7ecd\u548c\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u57fa\u7840\u7528\u6cd5<\/h3>\n<\/p>\n<p><p><code>input()<\/code> \u51fd\u6570\u4f1a\u6682\u505c\u7a0b\u5e8f\u7684\u6267\u884c\uff0c\u7b49\u5f85\u7528\u6237\u8f93\u5165\uff0c\u5e76\u8fd4\u56de\u8f93\u5165\u7684\u5b57\u7b26\u4e32\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u62ec\u53f7\u5185\u63d0\u4f9b\u63d0\u793a\u4fe1\u606f\u6765\u5f15\u5bfc\u7528\u6237\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u57fa\u7840\u7528\u6cd5\u793a\u4f8b<\/p>\n<p>user_input = input(&quot;\u8bf7\u8f93\u5165\u4e00\u4e9b\u5185\u5bb9: &quot;)<\/p>\n<p>print(f&quot;\u4f60\u8f93\u5165\u7684\u5185\u5bb9\u662f: {user_input}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u7c7b\u578b\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u7531\u4e8e <code>input()<\/code> \u51fd\u6570\u8fd4\u56de\u7684\u59cb\u7ec8\u662f\u5b57\u7b26\u4e32\uff0c\u5982\u679c\u9700\u8981\u5176\u4ed6\u7c7b\u578b\u7684\u6570\u636e\uff08\u5982\u6574\u6570\u3001\u6d6e\u70b9\u6570\uff09\uff0c\u5219\u9700\u8981\u8fdb\u884c\u7c7b\u578b\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u7c7b\u578b\u8f6c\u6362\u793a\u4f8b<\/p>\n<p>age = int(input(&quot;\u8bf7\u8f93\u5165\u4f60\u7684\u5e74\u9f84: &quot;))<\/p>\n<p>print(f&quot;\u4f60\u8f93\u5165\u7684\u5e74\u9f84\u662f: {age}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528 <code>argparse<\/code> \u6a21\u5757<\/h2>\n<\/p>\n<p><p><code>argparse<\/code> \u6a21\u5757\u7528\u4e8e\u4ece\u547d\u4ee4\u884c\u89e3\u6790\u53c2\u6570\u548c\u9009\u9879\uff0c\u9002\u7528\u4e8e\u9700\u8981\u4ece\u547d\u4ee4\u884c\u83b7\u53d6\u8f93\u5165\u7684\u60c5\u51b5\u3002\u5b83\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u529f\u80fd\u6765\u5904\u7406\u590d\u6742\u7684\u547d\u4ee4\u884c\u8f93\u5165\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u57fa\u7840\u7528\u6cd5<\/h3>\n<\/p>\n<p><p>\u9996\u5148\u9700\u8981\u5bfc\u5165 <code>argparse<\/code> \u6a21\u5757\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a\u89e3\u6790\u5668\u5bf9\u8c61\uff0c\u5e76\u6dfb\u52a0\u53c2\u6570\u5b9a\u4e49\u3002\u6700\u540e\u89e3\u6790\u547d\u4ee4\u884c\u53c2\u6570\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165argparse\u6a21\u5757<\/p>\n<p>import argparse<\/p>\n<h2><strong>\u521b\u5efa\u89e3\u6790\u5668\u5bf9\u8c61<\/strong><\/h2>\n<p>parser = argparse.ArgumentParser(description=&quot;\u793a\u4f8bargparse\u7a0b\u5e8f&quot;)<\/p>\n<h2><strong>\u6dfb\u52a0\u53c2\u6570\u5b9a\u4e49<\/strong><\/h2>\n<p>parser.add_argument(&quot;name&quot;, type=str, help=&quot;\u7528\u6237\u7684\u540d\u5b57&quot;)<\/p>\n<p>parser.add_argument(&quot;age&quot;, type=int, help=&quot;\u7528\u6237\u7684\u5e74\u9f84&quot;)<\/p>\n<h2><strong>\u89e3\u6790\u547d\u4ee4\u884c\u53c2\u6570<\/strong><\/h2>\n<p>args = parser.parse_args()<\/p>\n<h2><strong>\u6253\u5370\u89e3\u6790\u7ed3\u679c<\/strong><\/h2>\n<p>print(f&quot;\u540d\u5b57: {args.name}&quot;)<\/p>\n<p>print(f&quot;\u5e74\u9f84: {args.age}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u8be5\u811a\u672c\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u5982\u4e0b\u65b9\u5f0f\u63d0\u4f9b\u53c2\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python script.py John 25<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u9ad8\u7ea7\u7528\u6cd5<\/h3>\n<\/p>\n<p><p><code>argparse<\/code> \u6a21\u5757\u8fd8\u652f\u6301\u66f4\u591a\u9ad8\u7ea7\u529f\u80fd\uff0c\u5982\u53ef\u9009\u53c2\u6570\u3001\u9ed8\u8ba4\u503c\u3001\u53c2\u6570\u9a8c\u8bc1\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u9ad8\u7ea7\u7528\u6cd5\u793a\u4f8b<\/p>\n<p>parser = argparse.ArgumentParser(description=&quot;\u9ad8\u7ea7argparse\u793a\u4f8b&quot;)<\/p>\n<h2><strong>\u6dfb\u52a0\u53ef\u9009\u53c2\u6570<\/strong><\/h2>\n<p>parser.add_argument(&quot;--verbose&quot;, action=&quot;store_true&quot;, help=&quot;\u542f\u7528\u8be6\u7ec6\u6a21\u5f0f&quot;)<\/p>\n<p>parser.add_argument(&quot;--output&quot;, type=str, default=&quot;result.txt&quot;, help=&quot;\u8f93\u51fa\u6587\u4ef6\u8def\u5f84&quot;)<\/p>\n<h2><strong>\u89e3\u6790\u547d\u4ee4\u884c\u53c2\u6570<\/strong><\/h2>\n<p>args = parser.parse_args()<\/p>\n<h2><strong>\u4f7f\u7528\u89e3\u6790\u7ed3\u679c<\/strong><\/h2>\n<p>if args.verbose:<\/p>\n<p>    print(&quot;\u8be6\u7ec6\u6a21\u5f0f\u5df2\u542f\u7528&quot;)<\/p>\n<p>print(f&quot;\u8f93\u51fa\u6587\u4ef6\u8def\u5f84: {args.output}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u901a\u8fc7\u6587\u4ef6\u8bfb\u53d6\u8f93\u5165<\/h2>\n<\/p>\n<p><p>\u5f53\u9700\u8981\u4ece\u6587\u4ef6\u4e2d\u8bfb\u53d6\u8f93\u5165\u6570\u636e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684\u6587\u4ef6I\/O\u64cd\u4f5c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\u6216\u7ed3\u6784\u5316\u6570\u636e\u7684\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u8bfb\u53d6\u6587\u672c\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>open()<\/code> \u51fd\u6570\u6253\u5f00\u6587\u4ef6\uff0c\u5e76\u901a\u8fc7 <code>read()<\/code>\u3001<code>readline()<\/code> \u6216 <code>readlines()<\/code> \u65b9\u6cd5\u8bfb\u53d6\u6587\u4ef6\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bfb\u53d6\u6587\u672c\u6587\u4ef6\u793a\u4f8b<\/p>\n<p>with open(&quot;input.txt&quot;, &quot;r&quot;) as file:<\/p>\n<p>    content = file.read()<\/p>\n<p>    print(f&quot;\u6587\u4ef6\u5185\u5bb9:\\n{content}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8bfb\u53d6CSV\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u7ed3\u6784\u5316\u6570\u636e\uff08\u5982CSV\u6587\u4ef6\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>csv<\/code> \u6a21\u5757\u8fdb\u884c\u8bfb\u53d6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165csv\u6a21\u5757<\/p>\n<p>import csv<\/p>\n<h2><strong>\u8bfb\u53d6CSV\u6587\u4ef6\u793a\u4f8b<\/strong><\/h2>\n<p>with open(&quot;data.csv&quot;, &quot;r&quot;) as file:<\/p>\n<p>    reader = csv.reader(file)<\/p>\n<p>    for row in reader:<\/p>\n<p>        print(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u8bfb\u53d6JSON\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8eJSON\u683c\u5f0f\u7684\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>json<\/code> \u6a21\u5757\u8fdb\u884c\u8bfb\u53d6\u548c\u89e3\u6790\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165json\u6a21\u5757<\/p>\n<p>import json<\/p>\n<h2><strong>\u8bfb\u53d6JSON\u6587\u4ef6\u793a\u4f8b<\/strong><\/h2>\n<p>with open(&quot;data.json&quot;, &quot;r&quot;) as file:<\/p>\n<p>    data = json.load(file)<\/p>\n<p>    print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u901a\u8fc7\u56fe\u5f62\u7528\u6237\u754c\u9762\u83b7\u53d6\u8f93\u5165<\/h2>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u56fe\u5f62\u7528\u6237\u754c\u9762\u7684\u5e94\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>tkinter<\/code> \u6216 <code>PyQt<\/code> \u7b49\u5e93\u521b\u5efa\u8f93\u5165\u8868\u5355\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528 <code>tkinter<\/code><\/h3>\n<\/p>\n<p><p><code>tkinter<\/code> \u662fPython\u7684\u6807\u51c6GUI\u5e93\uff0c\u9002\u7528\u4e8e\u521b\u5efa\u7b80\u5355\u7684\u56fe\u5f62\u7528\u6237\u754c\u9762\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165tkinter\u6a21\u5757<\/p>\n<p>import tkinter as tk<\/p>\n<h2><strong>\u521b\u5efa\u4e3b\u7a97\u53e3<\/strong><\/h2>\n<p>root = tk.Tk()<\/p>\n<p>root.title(&quot;\u7528\u6237\u8f93\u5165\u793a\u4f8b&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u6807\u7b7e\u548c\u8f93\u5165\u6846<\/strong><\/h2>\n<p>label = tk.Label(root, text=&quot;\u8bf7\u8f93\u5165\u5185\u5bb9:&quot;)<\/p>\n<p>label.pack()<\/p>\n<p>entry = tk.Entry(root)<\/p>\n<p>entry.pack()<\/p>\n<h2><strong>\u521b\u5efa\u6309\u94ae\u548c\u56de\u8c03\u51fd\u6570<\/strong><\/h2>\n<p>def on_submit():<\/p>\n<p>    user_input = entry.get()<\/p>\n<p>    print(f&quot;\u4f60\u8f93\u5165\u7684\u5185\u5bb9\u662f: {user_input}&quot;)<\/p>\n<p>button = tk.Button(root, text=&quot;\u63d0\u4ea4&quot;, command=on_submit)<\/p>\n<p>button.pack()<\/p>\n<h2><strong>\u8fd0\u884c\u4e3b\u5faa\u73af<\/strong><\/h2>\n<p>root.m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>nloop()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528 <code>PyQt<\/code><\/h3>\n<\/p>\n<p><p><code>PyQt<\/code> \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684GUI\u5e93\uff0c\u9002\u7528\u4e8e\u521b\u5efa\u590d\u6742\u7684\u56fe\u5f62\u7528\u6237\u754c\u9762\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165PyQt\u6a21\u5757<\/p>\n<p>from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QVBoxLayout<\/p>\n<h2><strong>\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u5bf9\u8c61<\/strong><\/h2>\n<p>app = QApplication([])<\/p>\n<h2><strong>\u521b\u5efa\u4e3b\u7a97\u53e3<\/strong><\/h2>\n<p>window = QWidget()<\/p>\n<p>window.setWindowTitle(&quot;\u7528\u6237\u8f93\u5165\u793a\u4f8b&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u5e03\u5c40\u3001\u6807\u7b7e\u548c\u8f93\u5165\u6846<\/strong><\/h2>\n<p>layout = QVBoxLayout()<\/p>\n<p>label = QLabel(&quot;\u8bf7\u8f93\u5165\u5185\u5bb9:&quot;)<\/p>\n<p>layout.addWidget(label)<\/p>\n<p>entry = QLineEdit()<\/p>\n<p>layout.addWidget(entry)<\/p>\n<h2><strong>\u521b\u5efa\u6309\u94ae\u548c\u56de\u8c03\u51fd\u6570<\/strong><\/h2>\n<p>def on_submit():<\/p>\n<p>    user_input = entry.text()<\/p>\n<p>    print(f&quot;\u4f60\u8f93\u5165\u7684\u5185\u5bb9\u662f: {user_input}&quot;)<\/p>\n<p>button = QPushButton(&quot;\u63d0\u4ea4&quot;)<\/p>\n<p>button.clicked.connect(on_submit)<\/p>\n<p>layout.addWidget(button)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5e03\u5c40\u5e76\u663e\u793a\u7a97\u53e3<\/strong><\/h2>\n<p>window.setLayout(layout)<\/p>\n<p>window.show()<\/p>\n<h2><strong>\u8fd0\u884c\u5e94\u7528\u7a0b\u5e8f\u4e8b\u4ef6\u5faa\u73af<\/strong><\/h2>\n<p>app.exec_()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e94\u3001\u4ece\u7f51\u7edc\u83b7\u53d6\u8f93\u5165<\/h2>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u4ece\u7f51\u7edc\u83b7\u53d6\u8f93\u5165\uff0c\u4f8b\u5982\u4eceAPI\u6216\u7f51\u9875\u6293\u53d6\u6570\u636e\u3002\u53ef\u4ee5\u4f7f\u7528 <code>requests<\/code> \u6a21\u5757\u8fdb\u884cHTTP\u8bf7\u6c42\uff0c\u4ece\u800c\u83b7\u53d6\u6240\u9700\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u53d1\u9001GET\u8bf7\u6c42<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>requests.get()<\/code> \u65b9\u6cd5\u53d1\u9001HTTP GET\u8bf7\u6c42\uff0c\u5e76\u83b7\u53d6\u54cd\u5e94\u5185\u5bb9\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165requests\u6a21\u5757<\/p>\n<p>import requests<\/p>\n<h2><strong>\u53d1\u9001GET\u8bf7\u6c42\u793a\u4f8b<\/strong><\/h2>\n<p>response = requests.get(&quot;https:\/\/api.example.com\/data&quot;)<\/p>\n<p>if response.status_code == 200:<\/p>\n<p>    data = response.json()<\/p>\n<p>    print(data)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;\u8bf7\u6c42\u5931\u8d25\uff0c\u72b6\u6001\u7801: {response.status_code}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u53d1\u9001POST\u8bf7\u6c42<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>requests.post()<\/code> \u65b9\u6cd5\u53d1\u9001HTTP POST\u8bf7\u6c42\uff0c\u5e76\u4f20\u9012\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u53d1\u9001POST\u8bf7\u6c42\u793a\u4f8b<\/p>\n<p>payload = {&quot;key&quot;: &quot;value&quot;}<\/p>\n<p>response = requests.post(&quot;https:\/\/api.example.com\/data&quot;, json=payload)<\/p>\n<p>if response.status_code == 200:<\/p>\n<p>    data = response.json()<\/p>\n<p>    print(data)<\/p>\n<p>else:<\/p>\n<p>    print(f&quot;\u8bf7\u6c42\u5931\u8d25\uff0c\u72b6\u6001\u7801: {response.status_code}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u7f51\u9875\u6293\u53d6<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>BeautifulSoup<\/code> \u7b49\u5e93\u8fdb\u884c\u7f51\u9875\u6293\u53d6\uff0c\u4ee5\u83b7\u53d6\u7f51\u9875\u4e2d\u7684\u7279\u5b9a\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165requests\u548cBeautifulSoup\u6a21\u5757<\/p>\n<p>import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<h2><strong>\u53d1\u9001GET\u8bf7\u6c42\u5e76\u89e3\u6790\u7f51\u9875\u5185\u5bb9<\/strong><\/h2>\n<p>response = requests.get(&quot;https:\/\/www.example.com&quot;)<\/p>\n<p>soup = BeautifulSoup(response.content, &quot;html.parser&quot;)<\/p>\n<h2><strong>\u67e5\u627e\u5e76\u6253\u5370\u7279\u5b9a\u5143\u7d20<\/strong><\/h2>\n<p>title = soup.find(&quot;title&quot;).text<\/p>\n<p>print(f&quot;\u7f51\u9875\u6807\u9898: {title}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u516d\u3001\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u83b7\u53d6\u8f93\u5165<\/h2>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u4ece\u73af\u5883\u53d8\u91cf\u4e2d\u83b7\u53d6\u8f93\u5165\uff0c\u4f8b\u5982\u5728\u914d\u7f6e\u654f\u611f\u4fe1\u606f\u65f6\u3002\u53ef\u4ee5\u4f7f\u7528 <code>os<\/code> \u6a21\u5757\u8bfb\u53d6\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u8bfb\u53d6\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>os.environ<\/code> \u83b7\u53d6\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165os\u6a21\u5757<\/p>\n<p>import os<\/p>\n<h2><strong>\u8bfb\u53d6\u73af\u5883\u53d8\u91cf\u793a\u4f8b<\/strong><\/h2>\n<p>db_password = os.environ.get(&quot;DB_PASSWORD&quot;)<\/p>\n<p>if db_password:<\/p>\n<p>    print(f&quot;\u6570\u636e\u5e93\u5bc6\u7801: {db_password}&quot;)<\/p>\n<p>else:<\/p>\n<p>    print(&quot;\u73af\u5883\u53d8\u91cfDB_PASSWORD\u672a\u8bbe\u7f6e&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u4f7f\u7528 <code>export<\/code> \u547d\u4ee4\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf\uff0c\u6216\u5728Python\u811a\u672c\u4e2d\u4f7f\u7528 <code>os.environ<\/code> \u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\"># \u5728\u7ec8\u7aef\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<p>export DB_PASSWORD=&quot;your_password&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5728Python\u811a\u672c\u4e2d\u8bbe\u7f6e\u73af\u5883\u53d8\u91cf<\/p>\n<p>import os<\/p>\n<p>os.environ[&quot;DB_PASSWORD&quot;] = &quot;your_password&quot;<\/p>\n<p>print(f&quot;\u6570\u636e\u5e93\u5bc6\u7801: {os.environ.get(&#39;DB_PASSWORD&#39;)}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e03\u3001\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u83b7\u53d6\u8f93\u5165<\/h2>\n<\/p>\n<p><p>\u5728\u5927\u578b\u9879\u76ee\u4e2d\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528\u914d\u7f6e\u6587\u4ef6\u6765\u5b58\u50a8\u548c\u8bfb\u53d6\u914d\u7f6e\u4fe1\u606f\u3002\u53ef\u4ee5\u4f7f\u7528 <code>configparser<\/code> \u6a21\u5757\u8bfb\u53d6INI\u683c\u5f0f\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u8bfb\u53d6INI\u914d\u7f6e\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>configparser<\/code> \u6a21\u5757\u89e3\u6790INI\u683c\u5f0f\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u5e76\u83b7\u53d6\u914d\u7f6e\u4fe1\u606f\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165configparser\u6a21\u5757<\/p>\n<p>import configparser<\/p>\n<h2><strong>\u521b\u5efa\u914d\u7f6e\u89e3\u6790\u5668\u5bf9\u8c61<\/strong><\/h2>\n<p>config = configparser.ConfigParser()<\/p>\n<h2><strong>\u8bfb\u53d6\u914d\u7f6e\u6587\u4ef6<\/strong><\/h2>\n<p>config.read(&quot;config.ini&quot;)<\/p>\n<h2><strong>\u83b7\u53d6\u914d\u7f6e\u4fe1\u606f<\/strong><\/h2>\n<p>database_host = config.get(&quot;Database&quot;, &quot;Host&quot;)<\/p>\n<p>database_user = config.get(&quot;Database&quot;, &quot;User&quot;)<\/p>\n<p>database_password = config.get(&quot;Database&quot;, &quot;Password&quot;)<\/p>\n<p>print(f&quot;\u6570\u636e\u5e93\u4e3b\u673a: {database_host}&quot;)<\/p>\n<p>print(f&quot;\u6570\u636e\u5e93\u7528\u6237: {database_user}&quot;)<\/p>\n<p>print(f&quot;\u6570\u636e\u5e93\u5bc6\u7801: {database_password}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u5199\u5165INI\u914d\u7f6e\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>configparser<\/code> \u6a21\u5757\u5c06\u914d\u7f6e\u4fe1\u606f\u5199\u5165INI\u683c\u5f0f\u7684\u914d\u7f6e\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u914d\u7f6e\u89e3\u6790\u5668\u5bf9\u8c61<\/p>\n<p>config = configparser.ConfigParser()<\/p>\n<h2><strong>\u8bbe\u7f6e\u914d\u7f6e\u4fe1\u606f<\/strong><\/h2>\n<p>config[&quot;Database&quot;] = {<\/p>\n<p>    &quot;Host&quot;: &quot;localhost&quot;,<\/p>\n<p>    &quot;User&quot;: &quot;root&quot;,<\/p>\n<p>    &quot;Password&quot;: &quot;password&quot;<\/p>\n<p>}<\/p>\n<h2><strong>\u5199\u5165\u914d\u7f6e\u6587\u4ef6<\/strong><\/h2>\n<p>with open(&quot;config.ini&quot;, &quot;w&quot;) as configfile:<\/p>\n<p>    config.write(configfile)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u516b\u3001\u901a\u8fc7\u547d\u540d\u7ba1\u9053\u83b7\u53d6\u8f93\u5165<\/h2>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u9ad8\u7ea7\u5e94\u7528\u573a\u666f\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u901a\u8fc7\u547d\u540d\u7ba1\u9053\uff08FIFO\uff09\u8fdb\u884c\u8fdb\u7a0b\u95f4\u901a\u4fe1\u3002\u53ef\u4ee5\u4f7f\u7528 <code>os<\/code> \u6a21\u5757\u521b\u5efa\u548c\u8bfb\u53d6\u547d\u540d\u7ba1\u9053\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u521b\u5efa\u547d\u540d\u7ba1\u9053<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>os.mkfifo()<\/code> \u521b\u5efa\u547d\u540d\u7ba1\u9053\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165os\u6a21\u5757<\/p>\n<p>import os<\/p>\n<h2><strong>\u521b\u5efa\u547d\u540d\u7ba1\u9053\u793a\u4f8b<\/strong><\/h2>\n<p>fifo_path = &quot;\/tmp\/my_fifo&quot;<\/p>\n<p>if not os.path.exists(fifo_path):<\/p>\n<p>    os.mkfifo(fifo_path)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8bfb\u53d6\u547d\u540d\u7ba1\u9053<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>open()<\/code> \u51fd\u6570\u8bfb\u53d6\u547d\u540d\u7ba1\u9053\u4e2d\u7684\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bfb\u53d6\u547d\u540d\u7ba1\u9053\u793a\u4f8b<\/p>\n<p>with open(fifo_path, &quot;r&quot;) as fifo:<\/p>\n<p>    data = fifo.read()<\/p>\n<p>    print(f&quot;\u4ece\u547d\u540d\u7ba1\u9053\u8bfb\u53d6\u7684\u6570\u636e: {data}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u5199\u5165\u547d\u540d\u7ba1\u9053<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>open()<\/code> \u51fd\u6570\u5411\u547d\u540d\u7ba1\u9053\u4e2d\u5199\u5165\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5199\u5165\u547d\u540d\u7ba1\u9053\u793a\u4f8b<\/p>\n<p>with open(fifo_path, &quot;w&quot;) as fifo:<\/p>\n<p>    fifo.write(&quot;Hello from another process!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e5d\u3001\u4f7f\u7528\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b\u83b7\u53d6\u8f93\u5165<\/h2>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u590d\u6742\u573a\u666f\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u4f7f\u7528\u591a\u7ebf\u7a0b\u6216\u591a\u8fdb\u7a0b\u6765\u83b7\u53d6\u8f93\u5165\u3002\u53ef\u4ee5\u4f7f\u7528 <code>threading<\/code> \u548c <code>multiprocessing<\/code> \u6a21\u5757\u5b9e\u73b0\u5e76\u53d1\u8f93\u5165\u5904\u7406\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528\u591a\u7ebf\u7a0b<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>threading<\/code> \u6a21\u5757\u521b\u5efa\u548c\u7ba1\u7406\u7ebf\u7a0b\uff0c\u4ee5\u5b9e\u73b0\u5e76\u53d1\u8f93\u5165\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165threading\u6a21\u5757<\/p>\n<p>import threading<\/p>\n<h2><strong>\u5b9a\u4e49\u7ebf\u7a0b\u51fd\u6570<\/strong><\/h2>\n<p>def thread_function(name):<\/p>\n<p>    print(f&quot;\u7ebf\u7a0b {name} \u6b63\u5728\u8fd0\u884c&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u5e76\u542f\u52a8\u7ebf\u7a0b<\/strong><\/h2>\n<p>thread = threading.Thread(target=thread_function, args=(&quot;Thread-1&quot;,))<\/p>\n<p>thread.start()<\/p>\n<h2><strong>\u7b49\u5f85\u7ebf\u7a0b\u7ed3\u675f<\/strong><\/h2>\n<p>thread.join()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528\u591a\u8fdb\u7a0b<\/h3>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528 <code>multiprocessing<\/code> \u6a21\u5757\u521b\u5efa\u548c\u7ba1\u7406\u8fdb\u7a0b\uff0c\u4ee5\u5b9e\u73b0\u5e76\u53d1\u8f93\u5165\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5bfc\u5165multiprocessing\u6a21\u5757<\/p>\n<p>import multiprocessing<\/p>\n<h2><strong>\u5b9a\u4e49\u8fdb\u7a0b\u51fd\u6570<\/strong><\/h2>\n<p>def process_function(name):<\/p>\n<p>    print(f&quot;\u8fdb\u7a0b {name} \u6b63\u5728\u8fd0\u884c&quot;)<\/p>\n<h2><strong>\u521b\u5efa\u5e76\u542f\u52a8\u8fdb\u7a0b<\/strong><\/h2>\n<p>process = multiprocessing.Process(target=process_function, args=(&quot;Process-1&quot;,))<\/p>\n<p>process.start()<\/p>\n<h2><strong>\u7b49\u5f85\u8fdb\u7a0b\u7ed3\u675f<\/strong><\/h2>\n<p>process.join()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u5341\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86Python\u4e2d\u81ea\u5b9a\u4e49\u8f93\u5165\u7684\u591a\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528 <code>input()<\/code> \u51fd\u6570\u3001 <code>argparse<\/code> \u6a21\u5757\u3001\u901a\u8fc7\u6587\u4ef6\u8bfb\u53d6\u8f93\u5165\u3001\u901a\u8fc7\u56fe\u5f62\u7528\u6237\u754c\u9762\u83b7\u53d6\u8f93\u5165\u3001\u4ece\u7f51\u7edc\u83b7\u53d6\u8f93\u5165\u3001\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u83b7\u53d6\u8f93\u5165\u3001\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u83b7\u53d6\u8f93\u5165\u3001\u901a\u8fc7\u547d\u540d\u7ba1\u9053\u83b7\u53d6\u8f93\u5165\u4ee5\u53ca\u4f7f\u7528\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b\u83b7\u53d6\u8f93\u5165\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u9002\u7528\u7684\u573a\u666f\u548c\u7279\u70b9\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u3002<strong>\u901a\u8fc7\u7075\u6d3b\u8fd0\u7528\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u53ef\u4ee5\u5b9e\u73b0\u591a\u6837\u5316\u548c\u9ad8\u6548\u7684\u8f93\u5165\u5904\u7406<\/strong>\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u521b\u5efa\u81ea\u5b9a\u4e49\u8f93\u5165\u51fd\u6570\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5b9a\u4e49\u51fd\u6570\u6765\u521b\u5efa\u81ea\u5b9a\u4e49\u8f93\u5165\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\u6765\u63d0\u793a\u7528\u6237\u8f93\u5165\u7279\u5b9a\u7c7b\u578b\u7684\u6570\u636e\uff0c\u5e76\u8fdb\u884c\u9a8c\u8bc1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code class=\"language-python\">def custom_input(prompt):\n    while True:\n        user_input = input(prompt)\n        if user_input.isdigit():  # \u9a8c\u8bc1\u8f93\u5165\u662f\u5426\u4e3a\u6570\u5b57\n            return int(user_input)\n        else:\n            print(&quot;\u8bf7\u8f93\u5165\u4e00\u4e2a\u6709\u6548\u7684\u6570\u5b57\u3002&quot;)\n\nage = custom_input(&quot;\u8bf7\u8f93\u5165\u60a8\u7684\u5e74\u9f84: &quot;)\nprint(f&quot;\u60a8\u7684\u5e74\u9f84\u662f: {age}&quot;)\n<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c<code>custom_input<\/code>\u51fd\u6570\u4f1a\u6301\u7eed\u8bf7\u6c42\u7528\u6237\u8f93\u5165\uff0c\u76f4\u5230\u7528\u6237\u8f93\u5165\u4e00\u4e2a\u6709\u6548\u7684\u6570\u5b57\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u7528\u6237\u8f93\u5165\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u7528\u6237\u5728\u8f93\u5165\u65f6\u53ef\u80fd\u4f1a\u72af\u9519\uff0c\u5bfc\u81f4\u7a0b\u5e8f\u5d29\u6e83\u3002\u4e3a\u4e86\u63d0\u9ad8\u7528\u6237\u4f53\u9a8c\uff0c\u53ef\u4ee5\u901a\u8fc7\u5f02\u5e38\u5904\u7406\u6765\u6355\u83b7\u9519\u8bef\u3002\u4f7f\u7528<code>try<\/code>\u548c<code>except<\/code>\u8bed\u53e5\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u8f93\u5165\u9519\u8bef\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">def <a href=\"https:\/\/docs.pingcode.com\/agile\/agile-at-scale\/what-is-safe\" target=\"_blank\">SAFe<\/a>_input(prompt):\n    while True:\n        try:\n            user_input = input(prompt)\n            value = int(user_input)  # \u5c1d\u8bd5\u5c06\u8f93\u5165\u8f6c\u6362\u4e3a\u6574\u6570\n            return value\n        except ValueError:\n            print(&quot;\u8f93\u5165\u65e0\u6548\uff0c\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570\u3002&quot;)\n\nnumber = safe_input(&quot;\u8bf7\u8f93\u5165\u4e00\u4e2a\u6574\u6570: &quot;)\nprint(f&quot;\u60a8\u8f93\u5165\u7684\u6570\u5b57\u662f: {number}&quot;)\n<\/code><\/pre>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u786e\u4fdd\u7a0b\u5e8f\u4e0d\u4f1a\u56e0\u4e3a\u7528\u6237\u7684\u9519\u8bef\u8f93\u5165\u800c\u5d29\u6e83\uff0c\u5e76\u4e14\u4f1a\u6301\u7eed\u63d0\u793a\u7528\u6237\u76f4\u5230\u8f93\u5165\u6709\u6548\u3002<\/p>\n<p><strong>Python\u81ea\u5b9a\u4e49\u8f93\u5165\u7684\u5e94\u7528\u573a\u666f\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u81ea\u5b9a\u4e49\u8f93\u5165\u51fd\u6570\u5728\u591a\u4e2a\u573a\u666f\u4e2d\u975e\u5e38\u6709\u7528\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u4eec\u6765\u5904\u7406\u7528\u6237\u6ce8\u518c\u3001\u83b7\u53d6\u914d\u7f6e\u53c2\u6570\u6216\u6536\u96c6\u8c03\u67e5\u53cd\u9988\u3002\u5728\u9700\u8981\u7528\u6237\u8f93\u5165\u65f6\uff0c\u4f7f\u7528\u81ea\u5b9a\u4e49\u8f93\u5165\u53ef\u4ee5\u786e\u4fdd\u6570\u636e\u7684\u6709\u6548\u6027\u548c\u4e00\u81f4\u6027\u3002\u4f8b\u5982\uff0c\u5728\u5236\u4f5c\u6e38\u620f\u65f6\uff0c\u53ef\u4ee5\u8981\u6c42\u7528\u6237\u8f93\u5165\u89d2\u8272\u540d\u5e76\u68c0\u67e5\u662f\u5426\u7b26\u5408\u7279\u5b9a\u6761\u4ef6\u3002<\/p>\n<p>\u901a\u8fc7\u81ea\u5b9a\u4e49\u8f93\u5165\uff0c\u60a8\u53ef\u4ee5\u6839\u636e\u9879\u76ee\u9700\u6c42\u7075\u6d3b\u5904\u7406\u7528\u6237\u6570\u636e\uff0c\u4ece\u800c\u63d0\u5347\u4ee3\u7801\u7684\u53ef\u7ef4\u62a4\u6027\u548c\u7528\u6237\u7684\u4f53\u9a8c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u81ea\u5b9a\u4e49\u8f93\u5165\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4f8b\u5982\u4f7f\u7528 input() \u51fd\u6570\u3001 argparse \u6a21\u5757\u4ee5\u53ca\u521b\u5efa\u56fe\u5f62\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1178641,"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\/1178629"}],"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=1178629"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1178629\/revisions"}],"predecessor-version":[{"id":1178643,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1178629\/revisions\/1178643"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1178641"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1178629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1178629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1178629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}