{"id":1082359,"date":"2025-01-08T12:48:05","date_gmt":"2025-01-08T04:48:05","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1082359.html"},"modified":"2025-01-08T12:48:07","modified_gmt":"2025-01-08T04:48:07","slug":"%e5%a6%82%e4%bd%95%e5%b0%86%e7%a8%8b%e5%ba%8f%e5%af%bc%e5%85%a5python3-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1082359.html","title":{"rendered":"\u5982\u4f55\u5c06\u7a0b\u5e8f\u5bfc\u5165python3"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24183929\/ae60ddd9-ea77-4848-845f-356758c9de4a.webp\" alt=\"\u5982\u4f55\u5c06\u7a0b\u5e8f\u5bfc\u5165python3\" \/><\/p>\n<p><p> <strong>\u8981\u5c06\u7a0b\u5e8f\u5bfc\u5165Python3\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\uff1a\u4f7f\u7528import\u8bed\u53e5\u3001\u4f7f\u7528from&#8230;import\u8bed\u53e5\u3001\u4f7f\u7528__import__\u51fd\u6570\u3001\u6dfb\u52a0\u6587\u4ef6\u8def\u5f84\u5230sys.path\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528import\u8bed\u53e5\u8fdb\u884c\u6a21\u5757\u5bfc\u5165\u3002<\/strong> \u4f7f\u7528import\u8bed\u53e5\u662f\u6700\u5e38\u89c1\u4e14\u7b80\u5355\u7684\u65b9\u6cd5\u4e4b\u4e00\uff0c\u4f60\u53ea\u9700\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\u7f16\u5199<code>import<\/code>\uff0c\u7136\u540e\u8ddf\u4e0a\u4f60\u60f3\u8981\u5bfc\u5165\u7684\u6a21\u5757\u540d\u79f0\u5373\u53ef\u3002\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e\u5927\u591a\u6570\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528import\u8bed\u53e5<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u6807\u51c6\u5e93\u6a21\u5757<\/strong><br \/>Python\u81ea\u5e26\u4e86\u5f88\u591a\u6709\u7528\u7684\u6807\u51c6\u5e93\u6a21\u5757\uff0c\u4f60\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528import\u8bed\u53e5\u6765\u5bfc\u5165\u8fd9\u4e9b\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u8981\u4f7f\u7528\u6570\u5b66\u51fd\u6570\u6a21\u5757math\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>print(math.sqrt(16))  # \u8f93\u51fa4.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86math\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528\u4e86math\u6a21\u5757\u4e2d\u7684sqrt()\u51fd\u6570\u6765\u8ba1\u7b9716\u7684\u5e73\u65b9\u6839\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5bfc\u5165\u7b2c\u4e09\u65b9\u5e93\u6a21\u5757<\/strong><br \/>\u9664\u4e86\u6807\u51c6\u5e93\uff0cPython\u8fd8\u6709\u8bb8\u591a\u7b2c\u4e09\u65b9\u5e93\uff0c\u8fd9\u4e9b\u5e93\u9700\u8981\u5148\u901a\u8fc7pip\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528import\u8bed\u53e5\u6765\u5bfc\u5165\u3002\u4f8b\u5982\uff0c\u8981\u4f7f\u7528requests\u5e93\uff0c\u4f60\u9700\u8981\u5148\u5b89\u88c5\u5b83\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u53ef\u4ee5\u5728\u4f60\u7684Python\u811a\u672c\u4e2d\u5bfc\u5165requests\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>response = requests.get(&#39;http:\/\/www.example.com&#39;)<\/p>\n<p>print(response.status_code)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86requests\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528\u4e86requests\u6a21\u5757\u7684get()\u65b9\u6cd5\u6765\u53d1\u9001HTTP GET\u8bf7\u6c42\uff0c\u5e76\u6253\u5370\u54cd\u5e94\u7684\u72b6\u6001\u7801\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u4f7f\u7528from&#8230;import\u8bed\u53e5<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u7279\u5b9a\u51fd\u6570\u6216\u7c7b<\/strong><br \/>\u5982\u679c\u4f60\u53ea\u9700\u8981\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u67d0\u4e2a\u7279\u5b9a\u51fd\u6570\u6216\u7c7b\uff0c\u53ef\u4ee5\u4f7f\u7528from&#8230;import\u8bed\u53e5\u3002\u4f8b\u5982\uff0c\u53ea\u9700\u8981\u4f7f\u7528math\u6a21\u5757\u4e2d\u7684sqrt()\u51fd\u6570\uff0c\u53ef\u4ee5\u8fd9\u6837\u5199\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from math import sqrt<\/p>\n<p>print(sqrt(16))  # \u8f93\u51fa4.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528from&#8230;import\u8bed\u53e5\u53ea\u5bfc\u5165\u4e86math\u6a21\u5757\u4e2d\u7684sqrt()\u51fd\u6570\uff0c\u8fd9\u6837\u5728\u4f7f\u7528\u65f6\u5c31\u4e0d\u9700\u8981\u518d\u5199\u6a21\u5757\u540d\u4e86\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u591a\u4e2a\u51fd\u6570\u6216\u7c7b<\/strong><br \/>\u5982\u679c\u9700\u8981\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u591a\u4e2a\u51fd\u6570\u6216\u7c7b\uff0c\u53ef\u4ee5\u7528\u9017\u53f7\u5206\u9694\u5b83\u4eec\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from math import sqrt, pow<\/p>\n<p>print(sqrt(16))  # \u8f93\u51fa4.0<\/p>\n<p>print(pow(2, 3))  # \u8f93\u51fa8.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86math\u6a21\u5757\u4e2d\u7684sqrt()\u548cpow()\u51fd\u6570\uff0c\u5e76\u5206\u522b\u4f7f\u7528\u5b83\u4eec\u6765\u8ba1\u7b97\u5e73\u65b9\u6839\u548c\u5e42\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4f7f\u7528__import__\u51fd\u6570<\/p>\n<\/p>\n<ol>\n<li><strong>\u52a8\u6001\u5bfc\u5165\u6a21\u5757<\/strong><br \/>\u6709\u65f6\u5019\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u5728\u8fd0\u884c\u65f6\u52a8\u6001\u5bfc\u5165\u6a21\u5757\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684__import__\u51fd\u6570\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">module_name = &#39;math&#39;<\/p>\n<p>math_module = __import__(module_name)<\/p>\n<p>print(math_module.sqrt(16))  # \u8f93\u51fa4.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528__import__\u51fd\u6570\u52a8\u6001\u5bfc\u5165\u4e86math\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528math\u6a21\u5757\u4e2d\u7684sqrt()\u51fd\u6570\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5bfc\u5165\u5e26\u6709\u5b50\u6a21\u5757\u7684\u6a21\u5757<\/strong><br \/>\u5bf9\u4e8e\u5e26\u6709\u5b50\u6a21\u5757\u7684\u6a21\u5757\uff0c\u53ef\u4ee5\u901a\u8fc7__import__\u51fd\u6570\u7684\u7b2c\u4e8c\u4e2a\u53c2\u6570\u6765\u6307\u5b9a\u5bfc\u5165\u7684\u5c42\u7ea7\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">module_name = &#39;os.path&#39;<\/p>\n<p>path_module = __import__(module_name, fromlist=[&#39;&#39;])<\/p>\n<p>print(path_module.basename(&#39;\/usr\/bin\/python3&#39;))  # \u8f93\u51fapython3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528__import__\u51fd\u6570\u5bfc\u5165\u4e86os.path\u6a21\u5757\uff0c\u7136\u540e\u4f7f\u7528os.path\u6a21\u5757\u4e2d\u7684basename()\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u6dfb\u52a0\u6587\u4ef6\u8def\u5f84\u5230sys.path<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u81ea\u5b9a\u4e49\u6a21\u5757<\/strong><br \/>\u5982\u679c\u4f60\u9700\u8981\u5bfc\u5165\u4e00\u4e2a\u4e0d\u5728\u6807\u51c6\u5e93\u6216\u7b2c\u4e09\u65b9\u5e93\u4e2d\u7684\u81ea\u5b9a\u4e49\u6a21\u5757\uff0c\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u6587\u4ef6\u8def\u5f84\u5230sys.path\u6765\u5b9e\u73b0\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6a21\u5757my_module.py\uff0c\u5b83\u7684\u8def\u5f84\u662f\/home\/user\/my_project\/my_module.py\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>sys.path.append(&#39;\/home\/user\/my_project&#39;)<\/p>\n<p>import my_module<\/p>\n<p>my_module.my_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u9996\u5148\u901a\u8fc7sys.path.append()\u65b9\u6cd5\u5c06\u81ea\u5b9a\u4e49\u6a21\u5757\u6240\u5728\u7684\u8def\u5f84\u6dfb\u52a0\u5230sys.path\uff0c\u7136\u540e\u5bfc\u5165\u4e86my_module\u6a21\u5757\uff0c\u5e76\u4f7f\u7528\u4e86my_module\u6a21\u5757\u4e2d\u7684my_function()\u51fd\u6570\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5bfc\u5165\u540c\u4e00\u76ee\u5f55\u4e0b\u7684\u6a21\u5757<\/strong><br \/>\u5982\u679c\u4f60\u7684\u81ea\u5b9a\u4e49\u6a21\u5757\u4e0e\u5f53\u524d\u811a\u672c\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u3002\u4f8b\u5982\uff0c\u5047\u8bbe\u6709\u4e00\u4e2a\u81ea\u5b9a\u4e49\u6a21\u5757my_module.py\u4e0e\u5f53\u524d\u811a\u672c\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import my_module<\/p>\n<p>my_module.my_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u76f4\u63a5\u5bfc\u5165\u4e86\u4e0e\u5f53\u524d\u811a\u672c\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\u7684my_module\u6a21\u5757\uff0c\u5e76\u4f7f\u7528\u4e86my_module\u6a21\u5757\u4e2d\u7684my_function()\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u5176\u4ed6\u5bfc\u5165\u65b9\u5f0f<\/p>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u5305<\/strong><br \/>\u5305\u662f\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u6a21\u5757\u7684\u76ee\u5f55\uff0c\u901a\u8fc7\u5728\u76ee\u5f55\u4e2d\u6dfb\u52a0\u4e00\u4e2a__init__.py\u6587\u4ef6\u6765\u521b\u5efa\u5305\u3002\u53ef\u4ee5\u4f7f\u7528import\u8bed\u53e5\u5bfc\u5165\u5305\u4e2d\u7684\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u6709\u4e00\u4e2a\u5305my_package\uff0c\u91cc\u9762\u6709\u4e00\u4e2a\u6a21\u5757my_module.py\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import my_package.my_module<\/p>\n<p>my_package.my_module.my_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86my_package\u5305\u4e2d\u7684my_module\u6a21\u5757\uff0c\u5e76\u4f7f\u7528\u4e86my_module\u6a21\u5757\u4e2d\u7684my_function()\u51fd\u6570\u3002<\/p>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528\u522b\u540d<\/strong><br \/>\u4e3a\u4e86\u7b80\u5316\u4ee3\u7801\u6216\u907f\u514d\u547d\u540d\u51b2\u7a81\uff0c\u53ef\u4ee5\u4f7f\u7528as\u5173\u952e\u5b57\u7ed9\u6a21\u5757\u6216\u5305\u8d77\u4e00\u4e2a\u522b\u540d\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>array = np.array([1, 2, 3])<\/p>\n<p>print(array)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86numpy\u5e93\uff0c\u5e76\u7ed9\u5b83\u8d77\u4e86\u4e00\u4e2a\u522b\u540dnp\uff0c\u7136\u540e\u4f7f\u7528np.array()\u51fd\u6570\u521b\u5efa\u4e86\u4e00\u4e2a\u6570\u7ec4\u3002<\/p>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5bfc\u5165\u6240\u6709\u5185\u5bb9<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528\u661f\u53f7\uff08*\uff09\u5bfc\u5165\u6a21\u5757\u6216\u5305\u4e2d\u7684\u6240\u6709\u5185\u5bb9\uff0c\u4f46\u4e0d\u63a8\u8350\u8fd9\u79cd\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u53ef\u80fd\u5bfc\u81f4\u547d\u540d\u51b2\u7a81\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">from math import *<\/p>\n<p>print(sqrt(16))  # \u8f93\u51fa4.0<\/p>\n<p>print(pow(2, 3))  # \u8f93\u51fa8.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6bb5\u4ee3\u7801\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528from&#8230;import *\u8bed\u53e5\u5bfc\u5165\u4e86math\u6a21\u5757\u4e2d\u7684\u6240\u6709\u5185\u5bb9\uff0c\u5e76\u5206\u522b\u4f7f\u7528\u4e86sqrt()\u548cpow()\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><p>\u603b\u7ed3<\/p>\n<\/p>\n<p><p>\u5bfc\u5165Python3\u7a0b\u5e8f\u6709\u591a\u79cd\u65b9\u5f0f\uff0c\u5305\u62ec\u4f7f\u7528import\u8bed\u53e5\u3001from&#8230;import\u8bed\u53e5\u3001__import__\u51fd\u6570\uff0c\u4ee5\u53ca\u6dfb\u52a0\u6587\u4ef6\u8def\u5f84\u5230sys.path\u3002\u6bcf\u79cd\u65b9\u5f0f\u90fd\u6709\u5176\u9002\u7528\u573a\u666f\u548c\u4f18\u7f3a\u70b9\uff0c\u53ef\u4ee5\u6839\u636e\u5b9e\u9645\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5bfc\u5165\u65b9\u5f0f\u3002\u901a\u8fc7\u5408\u7406\u4f7f\u7528\u8fd9\u4e9b\u5bfc\u5165\u65b9\u5f0f\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\uff0c\u589e\u5f3a\u7a0b\u5e8f\u7684\u6a21\u5757\u5316\u548c\u7075\u6d3b\u6027\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06\u5df2\u6709\u7684\u4ee3\u7801\u6587\u4ef6\u5bfc\u5165\u5230Python 3\u4e2d\uff1f<\/strong><br \/>\u60a8\u53ef\u4ee5\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u5c06\u5176\u4ed6Python\u6587\u4ef6\uff08\u6a21\u5757\uff09\u5bfc\u5165\u5230\u60a8\u7684Python 3\u4ee3\u7801\u4e2d\u3002\u786e\u4fdd\u5c06\u4ee3\u7801\u6587\u4ef6\u653e\u5728\u76f8\u540c\u7684\u76ee\u5f55\u4e0b\uff0c\u6216\u5c06\u5176\u6240\u5728\u7684\u8def\u5f84\u6dfb\u52a0\u5230\u7cfb\u7edf\u7684<code>PYTHONPATH<\/code>\u4e2d\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<code>import filename<\/code>\uff0c\u5176\u4e2d<code>filename<\/code>\u662f\u60a8\u7684\u4ee3\u7801\u6587\u4ef6\u540d\uff08\u4e0d\u5305\u542b.py\u540e\u7f00\uff09\u3002<\/p>\n<p><strong>\u5728Python 3\u4e2d\u5982\u4f55\u5904\u7406\u5bfc\u5165\u6a21\u5757\u7684\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u5bfc\u5165\u6a21\u5757\u65f6\uff0c\u5982\u679c\u51fa\u73b0\u9519\u8bef\uff0c\u901a\u5e38\u662f\u56e0\u4e3a\u6a21\u5757\u672a\u627e\u5230\u6216\u8def\u5f84\u4e0d\u6b63\u786e\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u6587\u4ef6\u540d\u3001\u786e\u8ba4\u6587\u4ef6\u4f4d\u7f6e\u4ee5\u53ca\u4f7f\u7528\u7edd\u5bf9\u8def\u5f84\u6765\u6392\u67e5\u95ee\u9898\u3002\u4f7f\u7528<code>try-except<\/code>\u8bed\u53e5\u53ef\u4ee5\u6355\u6349\u5230<code>ImportError<\/code>\uff0c\u4ece\u800c\u5904\u7406\u76f8\u5173\u9519\u8bef\u5e76\u8fdb\u884c\u8c03\u8bd5\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python 3\u4e2d\u5bfc\u5165\u7279\u5b9a\u7684\u51fd\u6570\u6216\u7c7b\uff1f<\/strong><br \/>\u5982\u679c\u60a8\u53ea\u60f3\u5bfc\u5165\u67d0\u4e2a\u6a21\u5757\u4e2d\u7684\u7279\u5b9a\u51fd\u6570\u6216\u7c7b\uff0c\u53ef\u4ee5\u4f7f\u7528<code>from<\/code>\u8bed\u6cd5\u3002\u793a\u4f8b\uff1a<code>from module_name import function_name<\/code>\u3002\u8fd9\u5c06\u5141\u8bb8\u60a8\u76f4\u63a5\u4f7f\u7528<code>function_name<\/code>\u800c\u65e0\u9700\u524d\u7f00\u6a21\u5757\u540d\u3002\u786e\u4fdd\u5728\u5bfc\u5165\u4e4b\u524d\uff0c\u76ee\u6807\u51fd\u6570\u6216\u7c7b\u5728\u6a21\u5757\u4e2d\u662f\u53ef\u8bbf\u95ee\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5c06\u7a0b\u5e8f\u5bfc\u5165Python3\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\uff1a\u4f7f\u7528import\u8bed\u53e5\u3001\u4f7f\u7528from&#8230;import [&hellip;]","protected":false},"author":3,"featured_media":1082361,"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\/1082359"}],"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=1082359"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1082359\/revisions"}],"predecessor-version":[{"id":1082362,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1082359\/revisions\/1082362"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1082361"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1082359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1082359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1082359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}