{"id":1188470,"date":"2025-01-15T20:17:40","date_gmt":"2025-01-15T12:17:40","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1188470.html"},"modified":"2025-01-15T20:17:43","modified_gmt":"2025-01-15T12:17:43","slug":"python3-%e6%a8%a1%e5%9d%97%e5%a6%82%e4%bd%95%e5%af%bc%e5%85%a5","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1188470.html","title":{"rendered":"python3 \u6a21\u5757\u5982\u4f55\u5bfc\u5165"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25140748\/9c1a3ec4-46fa-4b79-82ba-122526ede23c.webp\" alt=\"python3 \u6a21\u5757\u5982\u4f55\u5bfc\u5165\" \/><\/p>\n<p><p> <strong>Python3 \u6a21\u5757\u5bfc\u5165\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\uff1aimport \u8bed\u53e5\u3001from&#8230;import \u8bed\u53e5\u3001import&#8230;as \u8bed\u53e5\u3001from&#8230;import&#8230;as \u8bed\u53e5\u3002\u5bfc\u5165\u65f6\u53ef\u4ee5\u9009\u62e9\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\u3001\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u67d0\u4e2a\u6216\u67d0\u4e9b\u51fd\u6570\u3001\u91cd\u547d\u540d\u5bfc\u5165\u7684\u6a21\u5757\u6216\u51fd\u6570\u3002<\/strong> \u5176\u4e2d\uff0c\u4f7f\u7528 import \u8bed\u53e5\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\u662f\u6700\u5e38\u89c1\u4e14\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u6a21\u5757\u4e2d\u7684\u6240\u6709\u51fd\u6570\u548c\u7c7b\u90fd\u53ef\u4ee5\u88ab\u8bbf\u95ee\uff0c\u4f46\u9700\u8981\u901a\u8fc7\u6a21\u5757\u540d\u8fdb\u884c\u8c03\u7528\uff0c\u53ef\u4ee5\u907f\u514d\u547d\u540d\u51b2\u7a81\u3002\u8be6\u7ec6\u63cf\u8ff0\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><p>\u4f7f\u7528import\u8bed\u53e5\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\u65f6\uff0c\u8bed\u6cd5\u4e3a\uff1a<code>import module_name<\/code>\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>print(math.sqrt(16))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5bfc\u5165\u4e86 Python \u7684\u6807\u51c6\u6570\u5b66\u6a21\u5757\uff0c\u5e76\u4f7f\u7528\u5176\u4e2d\u7684 sqrt \u51fd\u6570\u6765\u8ba1\u7b97 16 \u7684\u5e73\u65b9\u6839\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001IMPORT \u8bed\u53e5<\/h2>\n<\/p>\n<p><h3>1\u3001\u5bfc\u5165\u6574\u4e2a\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5728 Python \u4e2d\uff0c\u6700\u57fa\u672c\u7684\u6a21\u5757\u5bfc\u5165\u65b9\u5f0f\u662f\u4f7f\u7528 <code>import<\/code> \u8bed\u53e5\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\uff0c\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8ba9\u4f60\u8bbf\u95ee\u6a21\u5757\u4e2d\u7684\u6240\u6709\u5c5e\u6027\u548c\u65b9\u6cd5\uff0c\u4f46\u9700\u8981\u901a\u8fc7\u6a21\u5757\u540d\u8fdb\u884c\u8c03\u7528\uff0c\u53ef\u4ee5\u907f\u514d\u547d\u540d\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import module_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5bfc\u5165 Python \u6807\u51c6\u5e93\u4e2d\u7684 <code>math<\/code> \u6a21\u5757\uff0c\u5e76\u4f7f\u7528\u5176\u4e2d\u7684 <code>sqrt<\/code> \u51fd\u6570\u6765\u8ba1\u7b97\u5e73\u65b9\u6839\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>result = math.sqrt(25)<\/p>\n<p>print(result)  # \u8f93\u51fa\uff1a5.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u7684\u4f18\u70b9\u662f\u7b80\u5355\u660e\u4e86\uff0c\u53ef\u4ee5\u907f\u514d\u4e0e\u672c\u5730\u53d8\u91cf\u6216\u51fd\u6570\u540d\u53d1\u751f\u51b2\u7a81\uff0c\u4f46\u6bcf\u6b21\u8c03\u7528\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u6216\u53d8\u91cf\u65f6\u9700\u8981\u5e26\u4e0a\u6a21\u5757\u540d\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u90e8\u5206\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u6709\u65f6\u5019\uff0c\u6211\u4eec\u53ea\u9700\u8981\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u67d0\u4e2a\u51fd\u6570\u6216\u53d8\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>from...import<\/code> \u8bed\u53e5\uff0c\u53ea\u5bfc\u5165\u9700\u8981\u7684\u90e8\u5206\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from module_name import function_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u53ea\u5bfc\u5165 <code>math<\/code> \u6a21\u5757\u4e2d\u7684 <code>sqrt<\/code> \u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt<\/p>\n<p>result = sqrt(25)<\/p>\n<p>print(result)  # \u8f93\u51fa\uff1a5.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u4e0d\u8981\u4e0e\u672c\u5730\u53d8\u91cf\u6216\u51fd\u6570\u540d\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u6240\u6709\u5185\u5bb9<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u9700\u8981\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u6240\u6709\u5185\u5bb9\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>from...import *<\/code> \u8bed\u53e5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from module_name import *<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5bfc\u5165 <code>math<\/code> \u6a21\u5757\u4e2d\u7684\u6240\u6709\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import *<\/p>\n<p>result = sqrt(25)<\/p>\n<p>print(result)  # \u8f93\u51fa\uff1a5.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u6700\u4e3a\u7b80\u6d01\uff0c\u4f46\u5bb9\u6613\u9020\u6210\u547d\u540d\u51b2\u7a81\uff0c\u901a\u5e38\u4e0d\u63a8\u8350\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h2>\u4e8c\u3001IMPORT&#8230;AS \u8bed\u53e5<\/h2>\n<\/p>\n<p><h3>1\u3001\u4e3a\u6a21\u5757\u8d77\u522b\u540d<\/h3>\n<\/p>\n<p><p>\u5728\u5bfc\u5165\u6a21\u5757\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>as<\/code> \u5173\u952e\u5b57\u4e3a\u6a21\u5757\u8d77\u4e00\u4e2a\u522b\u540d\uff0c\u8fd9\u6837\u5728\u4f7f\u7528\u6a21\u5757\u65f6\u53ef\u4ee5\u901a\u8fc7\u522b\u540d\u6765\u5f15\u7528\uff0c\u4ee3\u7801\u4f1a\u66f4\u52a0\u7b80\u6d01\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import module_name as alias_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4e3a <code>math<\/code> \u6a21\u5757\u8d77\u522b\u540d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math as m<\/p>\n<p>result = m.sqrt(25)<\/p>\n<p>print(result)  # \u8f93\u51fa\uff1a5.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u548c\u53d8\u91cf\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4e3a\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u6216\u53d8\u91cf\u8d77\u522b\u540d<\/h3>\n<\/p>\n<p><p>\u540c\u6837\uff0c\u53ef\u4ee5\u4e3a\u6a21\u5757\u4e2d\u7684\u51fd\u6570\u6216\u53d8\u91cf\u8d77\u522b\u540d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from module_name import function_name as alias_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u4e3a <code>math<\/code> \u6a21\u5757\u4e2d\u7684 <code>sqrt<\/code> \u51fd\u6570\u8d77\u522b\u540d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from math import sqrt as square_root<\/p>\n<p>result = square_root(25)<\/p>\n<p>print(result)  # \u8f93\u51fa\uff1a5.0<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u7684\u4f18\u70b9\u662f\u4ee3\u7801\u66f4\u7b80\u6d01\uff0c\u53ef\u4ee5\u907f\u514d\u4e0e\u672c\u5730\u53d8\u91cf\u6216\u51fd\u6570\u540d\u51b2\u7a81\u3002<\/p>\n<\/p>\n<p><h2>\u4e09\u3001\u5bfc\u5165\u81ea\u5b9a\u4e49\u6a21\u5757<\/h2>\n<\/p>\n<p><h3>1\u3001\u5bfc\u5165\u540c\u4e00\u76ee\u5f55\u4e0b\u7684\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u5bfc\u5165 Python \u6807\u51c6\u5e93\u4e2d\u7684\u6a21\u5757\u5916\uff0c\u8fd8\u53ef\u4ee5\u5bfc\u5165\u81ea\u5b9a\u4e49\u6a21\u5757\u3002\u5047\u8bbe\u6709\u4e00\u4e2a <code>my_module.py<\/code> \u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># my_module.py<\/p>\n<p>def my_function():<\/p>\n<p>    print(&quot;Hello from my_module!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\u7684\u53e6\u4e00\u4e2a Python \u6587\u4ef6\u4e2d\u5bfc\u5165 <code>my_module<\/code> \u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import my_module<\/p>\n<p>my_module.my_function()  # \u8f93\u51fa\uff1aHello from my_module!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u5bfc\u5165\u4e0d\u540c\u76ee\u5f55\u4e0b\u7684\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u81ea\u5b9a\u4e49\u6a21\u5757\u4f4d\u4e8e\u4e0d\u540c\u7684\u76ee\u5f55\u4e0b\uff0c\u53ef\u4ee5\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165\u6216\u7edd\u5bf9\u5bfc\u5165\u7684\u65b9\u5f0f\u3002\u5047\u8bbe\u76ee\u5f55\u7ed3\u6784\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code>project\/<\/p>\n<p>    \u251c\u2500\u2500 m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.py<\/p>\n<p>    \u2514\u2500\u2500 my_package\/<\/p>\n<p>        \u2514\u2500\u2500 my_module.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u5728 <code>main.py<\/code> \u6587\u4ef6\u4e2d\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from .my_package import my_module<\/p>\n<p>my_module.my_function()  # \u8f93\u51fa\uff1aHello from my_module!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6216\u8005\u4f7f\u7528\u7edd\u5bf9\u5bfc\u5165\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from my_package import my_module<\/p>\n<p>my_module.my_function()  # \u8f93\u51fa\uff1aHello from my_module!<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u5bfc\u5165\u5305<\/h2>\n<\/p>\n<p><h3>1\u3001\u5bfc\u5165\u5305\u4e2d\u7684\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u4e00\u4e2a\u5305\u662f\u4e00\u4e2a\u5305\u542b\u591a\u4e2a\u6a21\u5757\u7684\u76ee\u5f55\uff0c\u76ee\u5f55\u4e2d\u5fc5\u987b\u5305\u542b\u4e00\u4e2a\u540d\u4e3a <code>__init__.py<\/code> \u7684\u6587\u4ef6\u3002\u5047\u8bbe\u6709\u4ee5\u4e0b\u76ee\u5f55\u7ed3\u6784\uff1a<\/p>\n<\/p>\n<p><pre><code>project\/<\/p>\n<p>    \u251c\u2500\u2500 main.py<\/p>\n<p>    \u2514\u2500\u2500 my_package\/<\/p>\n<p>        \u251c\u2500\u2500 __init__.py<\/p>\n<p>        \u251c\u2500\u2500 module1.py<\/p>\n<p>        \u2514\u2500\u2500 module2.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u5728 <code>main.py<\/code> \u6587\u4ef6\u4e2d\u5bfc\u5165 <code>my_package<\/code> \u5305\u4e2d\u7684\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from my_package import module1, module2<\/p>\n<p>module1.some_function()<\/p>\n<p>module2.another_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528 <code>__init__.py<\/code> \u6587\u4ef6<\/h3>\n<\/p>\n<p><p><code>__init__.py<\/code> \u6587\u4ef6\u53ef\u4ee5\u5305\u542b\u5305\u7684\u521d\u59cb\u5316\u4ee3\u7801\uff0c\u8fd8\u53ef\u4ee5\u63a7\u5236\u5305\u7684\u5bfc\u5165\u884c\u4e3a\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728 <code>__init__.py<\/code> \u6587\u4ef6\u4e2d\u5bfc\u5165\u5305\u4e2d\u7684\u6a21\u5757\uff0c\u4f7f\u5f97\u5728\u5bfc\u5165\u5305\u65f6\u81ea\u52a8\u5bfc\u5165\u8fd9\u4e9b\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># my_package\/__init__.py<\/p>\n<p>from .module1 import some_function<\/p>\n<p>from .module2 import another_function<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u5728 <code>main.py<\/code> \u6587\u4ef6\u4e2d\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u5305\u5e76\u4f7f\u7528\u6a21\u5757\u4e2d\u7684\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import my_package<\/p>\n<p>my_package.some_function()<\/p>\n<p>my_package.another_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e94\u3001\u6a21\u5757\u7684\u641c\u7d22\u8def\u5f84<\/h2>\n<\/p>\n<p><h3>1\u3001sys.path<\/h3>\n<\/p>\n<p><p>\u5f53\u5bfc\u5165\u6a21\u5757\u65f6\uff0cPython \u4f1a\u5728\u4e00\u7cfb\u5217\u76ee\u5f55\u4e2d\u641c\u7d22\u6a21\u5757\u3002\u8fd9\u4e9b\u76ee\u5f55\u7531 <code>sys.path<\/code> \u5217\u8868\u5b9a\u4e49\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539 <code>sys.path<\/code> \u6765\u6dfb\u52a0\u81ea\u5b9a\u4e49\u76ee\u5f55\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import sys<\/p>\n<p>sys.path.append(&#39;\/path\/to\/custom\/directory&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001PYTHONPATH \u73af\u5883\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u8fd8\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e <code>PYTHONPATH<\/code> \u73af\u5883\u53d8\u91cf\u6765\u6dfb\u52a0\u81ea\u5b9a\u4e49\u76ee\u5f55\u3002\u4f8b\u5982\uff0c\u5728 Unix \u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">export PYTHONPATH=\/path\/to\/custom\/directory<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728 Windows \u7cfb\u7edf\u4e0a\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-cmd\">set PYTHONPATH=C:\\path\\to\\custom\\directory<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8bbe\u7f6e <code>PYTHONPATH<\/code> \u73af\u5883\u53d8\u91cf\u540e\uff0cPython \u4f1a\u5728\u8fd9\u4e9b\u76ee\u5f55\u4e2d\u641c\u7d22\u6a21\u5757\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u6a21\u5757\u91cd\u8f7d<\/h2>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528 importlib.reload<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u5982\u679c\u4fee\u6539\u4e86\u6a21\u5757\u7684\u4ee3\u7801\uff0c\u9700\u8981\u91cd\u8f7d\u6a21\u5757\u4ee5\u4fbf\u91cd\u65b0\u52a0\u8f7d\u6700\u65b0\u7684\u4ee3\u7801\u3002\u53ef\u4ee5\u4f7f\u7528 <code>importlib.reload<\/code> \u51fd\u6570\u6765\u91cd\u8f7d\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import importlib<\/p>\n<p>import my_module<\/p>\n<h2><strong>\u4fee\u6539 my_module \u7684\u4ee3\u7801...<\/strong><\/h2>\n<p>importlib.reload(my_module)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u53ef\u4ee5\u786e\u4fdd\u4f7f\u7528\u6700\u65b0\u7684\u6a21\u5757\u4ee3\u7801\uff0c\u800c\u4e0d\u9700\u8981\u91cd\u65b0\u542f\u52a8 Python \u89e3\u91ca\u5668\u3002<\/p>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528 autoreload \u6269\u5c55<\/h3>\n<\/p>\n<p><p>\u5728 IPython \u6216 Jupyter Notebook \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>autoreload<\/code> \u6269\u5c55\u81ea\u52a8\u91cd\u8f7d\u6a21\u5757\u3002\u9996\u5148\u52a0\u8f7d\u6269\u5c55\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">%load_ext autoreload<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u542f\u7528\u81ea\u52a8\u91cd\u8f7d\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">%autoreload 2<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u5728\u6bcf\u6b21\u6267\u884c\u4ee3\u7801\u65f6\uff0c\u6240\u6709\u5bfc\u5165\u7684\u6a21\u5757\u90fd\u4f1a\u81ea\u52a8\u91cd\u8f7d\u3002<\/p>\n<\/p>\n<p><h2>\u4e03\u3001\u6a21\u5757\u7684\u7ec4\u7ec7\u548c\u7ba1\u7406<\/h2>\n<\/p>\n<p><h3>1\u3001\u5355\u6587\u4ef6\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u5c0f\u578b\u9879\u76ee\uff0c\u53ef\u4ee5\u5c06\u6240\u6709\u4ee3\u7801\u653e\u5728\u4e00\u4e2a\u5355\u6587\u4ef6\u6a21\u5757\u4e2d\u3002\u8fd9\u6837\u53ef\u4ee5\u51cf\u5c11\u6587\u4ef6\u6570\u91cf\uff0c\u65b9\u4fbf\u7ba1\u7406\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># my_module.py<\/p>\n<p>def function1():<\/p>\n<p>    pass<\/p>\n<p>def function2():<\/p>\n<p>    pass<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u591a\u6587\u4ef6\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u8f83\u5927\u578b\u7684\u9879\u76ee\uff0c\u53ef\u4ee5\u5c06\u4ee3\u7801\u5206\u6210\u591a\u4e2a\u6587\u4ef6\u6a21\u5757\uff0c\u6bcf\u4e2a\u6587\u4ef6\u6a21\u5757\u8d1f\u8d23\u4e0d\u540c\u7684\u529f\u80fd\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code>project\/<\/p>\n<p>    \u251c\u2500\u2500 main.py<\/p>\n<p>    \u251c\u2500\u2500 module1.py<\/p>\n<p>    \u251c\u2500\u2500 module2.py<\/p>\n<p>    \u2514\u2500\u2500 module3.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728 <code>main.py<\/code> \u6587\u4ef6\u4e2d\u5bfc\u5165\u8fd9\u4e9b\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import module1<\/p>\n<p>import module2<\/p>\n<p>import module3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5c06\u4ee3\u7801\u7ec4\u7ec7\u5f97\u66f4\u52a0\u6e05\u6670\uff0c\u65b9\u4fbf\u7ef4\u62a4\u548c\u6269\u5c55\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u5305\u7684\u7ec4\u7ec7<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u5927\u578b\u7684\u9879\u76ee\uff0c\u53ef\u4ee5\u5c06\u4ee3\u7801\u7ec4\u7ec7\u6210\u591a\u4e2a\u5305\uff0c\u6bcf\u4e2a\u5305\u5305\u542b\u591a\u4e2a\u6a21\u5757\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code>project\/<\/p>\n<p>    \u251c\u2500\u2500 main.py<\/p>\n<p>    \u251c\u2500\u2500 package1\/<\/p>\n<p>    \u2502   \u251c\u2500\u2500 __init__.py<\/p>\n<p>    \u2502   \u251c\u2500\u2500 module1.py<\/p>\n<p>    \u2502   \u2514\u2500\u2500 module2.py<\/p>\n<p>    \u2514\u2500\u2500 package2\/<\/p>\n<p>        \u251c\u2500\u2500 __init__.py<\/p>\n<p>        \u251c\u2500\u2500 module3.py<\/p>\n<p>        \u2514\u2500\u2500 module4.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728 <code>main.py<\/code> \u6587\u4ef6\u4e2d\u5bfc\u5165\u8fd9\u4e9b\u5305\u548c\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from package1 import module1, module2<\/p>\n<p>from package2 import module3, module4<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5c06\u4ee3\u7801\u7ec4\u7ec7\u5f97\u66f4\u52a0\u6a21\u5757\u5316\uff0c\u65b9\u4fbf\u56e2\u961f\u534f\u4f5c\u548c\u4ee3\u7801\u590d\u7528\u3002<\/p>\n<\/p>\n<p><h2>\u516b\u3001\u6a21\u5757\u7684\u6587\u6863\u548c\u6ce8\u91ca<\/h2>\n<\/p>\n<p><h3>1\u3001\u6a21\u5757\u6587\u6863\u5b57\u7b26\u4e32<\/h3>\n<\/p>\n<p><p>\u5728\u6a21\u5757\u6587\u4ef6\u7684\u5f00\u5934\uff0c\u53ef\u4ee5\u6dfb\u52a0\u6a21\u5757\u7684\u6587\u6863\u5b57\u7b26\u4e32\uff0c\u7b80\u8981\u8bf4\u660e\u6a21\u5757\u7684\u529f\u80fd\u548c\u4f7f\u7528\u65b9\u6cd5\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">&quot;&quot;&quot;<\/p>\n<p>my_module.py<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u793a\u4f8b\u6a21\u5757\uff0c\u5305\u542b\u4e00\u4e9b\u793a\u4f8b\u51fd\u6570\u3002<\/p>\n<p>&quot;&quot;&quot;<\/p>\n<p>def function1():<\/p>\n<p>    &quot;&quot;&quot;\u8fd9\u662f function1 \u7684\u6587\u6863\u5b57\u7b26\u4e32\u3002&quot;&quot;&quot;<\/p>\n<p>    pass<\/p>\n<p>def function2():<\/p>\n<p>    &quot;&quot;&quot;\u8fd9\u662f function2 \u7684\u6587\u6863\u5b57\u7b26\u4e32\u3002&quot;&quot;&quot;<\/p>\n<p>    pass<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6587\u6863\u5b57\u7b26\u4e32\u53ef\u4ee5\u901a\u8fc7 <code>help<\/code> \u51fd\u6570\u67e5\u770b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import my_module<\/p>\n<p>help(my_module)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u51fd\u6570\u548c\u7c7b\u7684\u6ce8\u91ca<\/h3>\n<\/p>\n<p><p>\u5728\u51fd\u6570\u548c\u7c7b\u7684\u5b9a\u4e49\u4e2d\uff0c\u53ef\u4ee5\u6dfb\u52a0\u6ce8\u91ca\uff0c\u8bf4\u660e\u51fd\u6570\u548c\u7c7b\u7684\u7528\u9014\u3001\u53c2\u6570\u3001\u8fd4\u56de\u503c\u7b49\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def add(a, b):<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u8ba1\u7b97\u4e24\u4e2a\u6570\u7684\u548c\u3002<\/p>\n<p>    \u53c2\u6570\uff1a<\/p>\n<p>    a -- \u7b2c\u4e00\u4e2a\u6570<\/p>\n<p>    b -- \u7b2c\u4e8c\u4e2a\u6570<\/p>\n<p>    \u8fd4\u56de\u503c\uff1a<\/p>\n<p>    \u4e24\u4e2a\u6570\u7684\u548c<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    return a + b<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u6ce8\u91ca\u53ef\u4ee5\u5e2e\u52a9\u5176\u4ed6\u5f00\u53d1\u8005\u7406\u89e3\u4ee3\u7801\u7684\u529f\u80fd\u548c\u4f7f\u7528\u65b9\u6cd5\uff0c\u63d0\u5347\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027\u3002<\/p>\n<\/p>\n<p><h2>\u4e5d\u3001\u5e38\u89c1\u95ee\u9898\u548c\u89e3\u51b3\u65b9\u6cd5<\/h2>\n<\/p>\n<p><h3>1\u3001\u6a21\u5757\u672a\u627e\u5230<\/h3>\n<\/p>\n<p><p>\u5728\u5bfc\u5165\u6a21\u5757\u65f6\uff0c\u5982\u679c\u51fa\u73b0 <code>ModuleNotFoundError<\/code> \u9519\u8bef\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u6a21\u5757\u672a\u5b89\u88c5\u6216\u6a21\u5757\u8def\u5f84\u4e0d\u6b63\u786e\u3002\u53ef\u4ee5\u68c0\u67e5\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u786e\u8ba4\u6a21\u5757\u5df2\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>pip install module_name<\/code> \u5b89\u88c5\u6a21\u5757\u3002<\/li>\n<li>\u68c0\u67e5\u6a21\u5757\u8def\u5f84\u662f\u5426\u5728 <code>sys.path<\/code> \u5217\u8868\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>print(sys.path)<\/code> \u67e5\u770b\u6a21\u5757\u641c\u7d22\u8def\u5f84\u3002<\/li>\n<li>\u786e\u8ba4\u6a21\u5757\u6587\u4ef6\u540d\u548c\u5bfc\u5165\u8bed\u53e5\u4e2d\u6a21\u5757\u540d\u4e00\u81f4\uff0c\u6ce8\u610f\u5927\u5c0f\u5199\u3002<\/li>\n<\/ul>\n<p><h3>2\u3001\u6a21\u5757\u547d\u540d\u51b2\u7a81<\/h3>\n<\/p>\n<p><p>\u5728\u5bfc\u5165\u6a21\u5757\u65f6\uff0c\u5982\u679c\u51fa\u73b0\u547d\u540d\u51b2\u7a81\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>as<\/code> \u5173\u952e\u5b57\u4e3a\u6a21\u5757\u6216\u51fd\u6570\u8d77\u522b\u540d\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import module1 as m1<\/p>\n<p>import module2 as m2<\/p>\n<p>m1.function()<\/p>\n<p>m2.function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u547d\u540d\u51b2\u7a81\uff0c\u786e\u4fdd\u4ee3\u7801\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u5faa\u73af\u5bfc\u5165<\/h3>\n<\/p>\n<p><p>\u5728\u591a\u4e2a\u6a21\u5757\u76f8\u4e92\u5bfc\u5165\u65f6\uff0c\u53ef\u80fd\u4f1a\u51fa\u73b0\u5faa\u73af\u5bfc\u5165\u7684\u95ee\u9898\uff0c\u5bfc\u81f4 <code>ImportError<\/code> \u9519\u8bef\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u89e3\u51b3\uff1a<\/p>\n<\/p>\n<ul>\n<li>\u91cd\u65b0\u7ec4\u7ec7\u4ee3\u7801\uff0c\u907f\u514d\u5faa\u73af\u5bfc\u5165\u3002\u4f8b\u5982\uff0c\u5c06\u5171\u540c\u4f9d\u8d56\u7684\u90e8\u5206\u63d0\u53d6\u5230\u4e00\u4e2a\u5355\u72ec\u7684\u6a21\u5757\u4e2d\u3002<\/li>\n<li>\u4f7f\u7528\u5ef6\u8fdf\u5bfc\u5165\uff0c\u5728\u9700\u8981\u65f6\u518d\u5bfc\u5165\u6a21\u5757\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<p><pre><code class=\"language-python\"># module1.py<\/p>\n<p>def function1():<\/p>\n<p>    from module2 import function2<\/p>\n<p>    function2()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u53ef\u4ee5\u907f\u514d\u5faa\u73af\u5bfc\u5165\uff0c\u786e\u4fdd\u4ee3\u7801\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h2>\u5341\u3001\u6a21\u5757\u7684\u53d1\u5e03\u548c\u5b89\u88c5<\/h2>\n<\/p>\n<p><h3>1\u3001\u521b\u5efa setup.py \u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u8981\u53d1\u5e03\u4e00\u4e2a Python \u6a21\u5757\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a <code>setup.py<\/code> \u6587\u4ef6\uff0c\u5305\u542b\u6a21\u5757\u7684\u5143\u6570\u636e\u548c\u5b89\u88c5\u4fe1\u606f\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from setuptools import setup, find_packages<\/p>\n<p>setup(<\/p>\n<p>    name=&#39;my_module&#39;,<\/p>\n<p>    version=&#39;0.1&#39;,<\/p>\n<p>    packages=find_packages(),<\/p>\n<p>    install_requires=[<\/p>\n<p>        &#39;numpy&#39;,<\/p>\n<p>        &#39;pandas&#39;,<\/p>\n<p>    ],<\/p>\n<p>    author=&#39;Your Name&#39;,<\/p>\n<p>    author_email=&#39;your.email@example.com&#39;,<\/p>\n<p>    description=&#39;A sample Python module&#39;,<\/p>\n<p>    url=&#39;https:\/\/github.com\/yourusername\/my_module&#39;,<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u751f\u6210\u5206\u53d1\u5305<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528 <code>setup.py<\/code> \u6587\u4ef6\uff0c\u53ef\u4ee5\u751f\u6210\u6e90\u4ee3\u7801\u5206\u53d1\u5305\u548c\u4e8c\u8fdb\u5236\u5206\u53d1\u5305\u3002\u9996\u5148\u5b89\u88c5 <code>wheel<\/code> \u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install wheel<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210\u5206\u53d1\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py sdist bdist_wheel<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u751f\u6210\u7684\u5206\u53d1\u5305\u4f1a\u4fdd\u5b58\u5728 <code>dist<\/code> \u76ee\u5f55\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>3\u3001\u53d1\u5e03\u5230 PyPI<\/h3>\n<\/p>\n<p><p>\u8981\u5c06\u6a21\u5757\u53d1\u5e03\u5230 Python \u5305\u7d22\u5f15\uff08PyPI\uff09\uff0c\u9996\u5148\u9700\u8981\u6ce8\u518c\u4e00\u4e2a PyPI \u8d26\u53f7\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a API \u4ee4\u724c\u3002\u7136\u540e\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u53d1\u5e03\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install twine<\/p>\n<p>twine upload dist\/*<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53d1\u5e03\u6210\u529f\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7 <code>pip install my_module<\/code> \u5b89\u88c5\u6a21\u5757\uff0c\u5e76\u5728\u4ee3\u7801\u4e2d\u4f7f\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import my_module<\/p>\n<p>my_module.some_function()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u53ef\u4ee5\u5c06\u81ea\u5df1\u7684 Python \u6a21\u5757\u53d1\u5e03\u5230 PyPI\uff0c\u65b9\u4fbf\u5176\u4ed6\u5f00\u53d1\u8005\u5b89\u88c5\u548c\u4f7f\u7528\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python3\u4e2d\u5bfc\u5165\u81ea\u5b9a\u4e49\u6a21\u5757\uff1f<\/strong><br \/>\u5728Python3\u4e2d\uff0c\u5bfc\u5165\u81ea\u5b9a\u4e49\u6a21\u5757\u7684\u6b65\u9aa4\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u6a21\u5757\u6587\u4ef6\uff08\u4f8b\u5982my_module.py\uff09\u4e0e\u4e3b\u811a\u672c\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u5bfc\u5165\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u6a21\u5757\u540d\u4e3amy_module\uff0c\u53ea\u9700\u5728\u4e3b\u811a\u672c\u4e2d\u5199<code>import my_module<\/code>\u5373\u53ef\u3002\u5982\u679c\u9700\u8981\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u7279\u5b9a\u529f\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528<code>from my_module import function_name<\/code>\u8bed\u53e5\u3002\u8fd9\u6837\uff0c\u4f60\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u8be5\u51fd\u6570\u800c\u65e0\u9700\u6a21\u5757\u540d\u524d\u7f00\u3002<\/p>\n<p><strong>\u5bfc\u5165\u6a21\u5757\u65f6\u9047\u5230ImportError\u8be5\u5982\u4f55\u89e3\u51b3\uff1f<\/strong><br \/>\u5f53\u4f60\u5728\u5bfc\u5165\u6a21\u5757\u65f6\u9047\u5230ImportError\uff0c\u901a\u5e38\u662f\u56e0\u4e3aPython\u65e0\u6cd5\u627e\u5230\u6307\u5b9a\u7684\u6a21\u5757\u3002\u8fd9\u53ef\u80fd\u662f\u7531\u4e8e\u6a21\u5757\u540d\u79f0\u62fc\u5199\u9519\u8bef\u3001\u6a21\u5757\u4e0d\u5728Python\u7684\u641c\u7d22\u8def\u5f84\u4e2d\u6216\u8005\u6a21\u5757\u672a\u5b89\u88c5\u3002\u68c0\u67e5\u6a21\u5757\u540d\u79f0\u662f\u5426\u6b63\u786e\uff0c\u786e\u4fdd\u6a21\u5757\u6587\u4ef6\u5728\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55\u4e2d\uff0c\u6216\u4f7f\u7528<code>sys.path.append(&#39;your_module_path&#39;)<\/code>\u6dfb\u52a0\u6a21\u5757\u6240\u5728\u8def\u5f84\u3002\u5982\u679c\u662f\u7b2c\u4e09\u65b9\u6a21\u5757\uff0c\u786e\u4fdd\u5df2\u7ecf\u901a\u8fc7pip\u5b89\u88c5\u3002<\/p>\n<p><strong>Python3\u4e2d\u7684\u6a21\u5757\u5bfc\u5165\u987a\u5e8f\u662f\u5426\u4f1a\u5f71\u54cd\u7a0b\u5e8f\u8fd0\u884c\uff1f<\/strong><br \/>\u5728Python3\u4e2d\uff0c\u6a21\u5757\u5bfc\u5165\u7684\u987a\u5e8f\u786e\u5b9e\u53ef\u80fd\u5f71\u54cd\u7a0b\u5e8f\u7684\u8fd0\u884c\u3002\u5982\u679c\u4e00\u4e2a\u6a21\u5757\u4f9d\u8d56\u4e8e\u53e6\u4e00\u4e2a\u6a21\u5757\uff0c\u786e\u4fdd\u5148\u5bfc\u5165\u4f9d\u8d56\u7684\u6a21\u5757\u3002\u5faa\u73af\u5bfc\u5165\u53ef\u80fd\u5bfc\u81f4\u95ee\u9898\uff0c\u5c24\u5176\u662f\u5f53\u6a21\u5757\u95f4\u76f8\u4e92\u4f9d\u8d56\u65f6\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5\uff0c\u53ef\u4ee5\u91cd\u6784\u4ee3\u7801\uff0c\u5c06\u76f8\u4e92\u4f9d\u8d56\u7684\u529f\u80fd\u653e\u5165\u540c\u4e00\u4e2a\u6a21\u5757\u4e2d\uff0c\u6216\u4f7f\u7528\u51fd\u6570\u5ef6\u8fdf\u8c03\u7528\u7b49\u7b56\u7565\u4ee5\u786e\u4fdd\u6a21\u5757\u7684\u6b63\u786e\u52a0\u8f7d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python3 \u6a21\u5757\u5bfc\u5165\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u4e3b\u8981\u5305\u62ec\uff1aimport \u8bed\u53e5\u3001from&#8230;import \u8bed\u53e5\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1188478,"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\/1188470"}],"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=1188470"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1188470\/revisions"}],"predecessor-version":[{"id":1188479,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1188470\/revisions\/1188479"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1188478"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1188470"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1188470"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1188470"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}