{"id":1139814,"date":"2025-01-08T22:14:00","date_gmt":"2025-01-08T14:14:00","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1139814.html"},"modified":"2025-01-08T22:14:02","modified_gmt":"2025-01-08T14:14:02","slug":"python%e5%a6%82%e4%bd%95%e5%af%bc%e5%85%a5%e5%8f%a6%e4%b8%80%e4%b8%aa%e6%96%87%e4%bb%b6%e7%9a%84%e5%8f%98%e9%87%8f","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1139814.html","title":{"rendered":"python\u5982\u4f55\u5bfc\u5165\u53e6\u4e00\u4e2a\u6587\u4ef6\u7684\u53d8\u91cf"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25103005\/cffdcbb5-5e8c-479f-88c7-2ca197c7bfa4.webp\" alt=\"python\u5982\u4f55\u5bfc\u5165\u53e6\u4e00\u4e2a\u6587\u4ef6\u7684\u53d8\u91cf\" \/><\/p>\n<p><p> <strong>Python\u5bfc\u5165\u53e6\u4e00\u4e2a\u6587\u4ef6\u7684\u53d8\u91cf\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528import\u8bed\u53e5\u3001from&#8230;import\u8bed\u53e5\u7b49\u3002<\/strong> \u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u4e00\u4e9b\u5b9e\u7528\u7684\u4ee3\u7801\u793a\u4f8b\uff0c\u5e2e\u52a9\u8bfb\u8005\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u6280\u672f\u3002<strong>\u4f7f\u7528import\u8bed\u53e5\u5bfc\u5165\u6587\u4ef6\u3001\u4f7f\u7528from&#8230;import\u8bed\u53e5\u5bfc\u5165\u7279\u5b9a\u53d8\u91cf\u3001\u4f7f\u7528__init__.py\u6587\u4ef6\u7ba1\u7406\u5305\u3001\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165\u3001\u5904\u7406\u5bfc\u5165\u65f6\u7684\u5faa\u73af\u4f9d\u8d56\u95ee\u9898<\/strong>\u3002\u6211\u4eec\u5c06\u5bf9\u201c\u4f7f\u7528import\u8bed\u53e5\u5bfc\u5165\u6587\u4ef6\u201d\u8fdb\u884c\u8be6\u7ec6\u63cf\u8ff0\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528import\u8bed\u53e5\u5bfc\u5165\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u662fPython\u4e2d\u6700\u57fa\u672c\u7684\u5bfc\u5165\u65b9\u5f0f\u4e4b\u4e00\u3002\u8fd9\u4e2a\u65b9\u6cd5\u5141\u8bb8\u4f60\u5bfc\u5165\u6574\u4e2a\u6a21\u5757\uff0c\u7136\u540e\u901a\u8fc7\u6a21\u5757\u540d\u8bbf\u95ee\u5176\u4e2d\u7684\u53d8\u91cf\u548c\u51fd\u6570\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e24\u4e2a\u6587\u4ef6\uff1a<code>file_a.py<\/code>\u548c<code>file_b.py<\/code>\u3002\u5728<code>file_a.py<\/code>\u4e2d\u5b9a\u4e49\u4e86\u4e00\u4e9b\u53d8\u91cf\u548c\u51fd\u6570\uff0c\u6211\u4eec\u5e0c\u671b\u5728<code>file_b.py<\/code>\u4e2d\u4f7f\u7528\u5b83\u4eec\u3002<\/p>\n<\/p>\n<p><h4>\u6587\u4ef6\u793a\u4f8b<\/h4>\n<\/p>\n<p><p><strong>file_a.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_a.py<\/p>\n<p>variable_a = &quot;Hello from file_a!&quot;<\/p>\n<p>def function_a():<\/p>\n<p>    return &quot;This is function_a from file_a!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>file_b.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_b.py<\/p>\n<p>import file_a<\/p>\n<p>print(file_a.variable_a)<\/p>\n<p>print(file_a.function_a())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>import file_a<\/code>\u5c06<code>file_a.py<\/code>\u4e2d\u7684\u5185\u5bb9\u5bfc\u5165\u5230<code>file_b.py<\/code>\u4e2d\u3002\u7136\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7<code>file_a.variable_a<\/code>\u548c<code>file_a.function_a()<\/code>\u6765\u8bbf\u95ee\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u548c\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>\u4f18\u70b9<\/h4>\n<\/p>\n<ol>\n<li><strong>\u7b80\u5355\u76f4\u63a5<\/strong>\uff1a\u8fd9\u79cd\u65b9\u6cd5\u975e\u5e38\u76f4\u89c2\uff0c\u9002\u5408\u521d\u5b66\u8005\u3002<\/li>\n<li><strong>\u547d\u540d\u7a7a\u95f4\u6e05\u6670<\/strong>\uff1a\u6240\u6709\u5bfc\u5165\u7684\u53d8\u91cf\u548c\u51fd\u6570\u90fd\u4f4d\u4e8e<code>file_a<\/code>\u7684\u547d\u540d\u7a7a\u95f4\u4e0b\uff0c\u907f\u514d\u4e86\u547d\u540d\u51b2\u7a81\u3002<\/li>\n<\/ol>\n<p><h4>\u7f3a\u70b9<\/h4>\n<\/p>\n<ol>\n<li><strong>\u5197\u957f<\/strong>\uff1a\u6bcf\u6b21\u8bbf\u95ee\u53d8\u91cf\u6216\u51fd\u6570\u65f6\u90fd\u9700\u8981\u4f7f\u7528\u6a21\u5757\u540d\u524d\u7f00\uff0c\u8fd9\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u663e\u5f97\u5197\u957f\u3002<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u4f7f\u7528from&#8230;import\u8bed\u53e5\u5bfc\u5165\u7279\u5b9a\u53d8\u91cf<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u53ea\u9700\u8981\u5bfc\u5165\u7279\u5b9a\u7684\u53d8\u91cf\u6216\u51fd\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528<code>from...import<\/code>\u8bed\u53e5\u3002\u8fd9\u79cd\u65b9\u6cd5\u5141\u8bb8\u4f60\u76f4\u63a5\u5bfc\u5165\u6240\u9700\u7684\u53d8\u91cf\u6216\u51fd\u6570\uff0c\u800c\u65e0\u9700\u4f7f\u7528\u6a21\u5757\u540d\u524d\u7f00\u3002<\/p>\n<\/p>\n<p><h4>\u6587\u4ef6\u793a\u4f8b<\/h4>\n<\/p>\n<p><p><strong>file_a.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_a.py<\/p>\n<p>variable_a = &quot;Hello from file_a!&quot;<\/p>\n<p>def function_a():<\/p>\n<p>    return &quot;This is function_a from file_a!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>file_b.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_b.py<\/p>\n<p>from file_a import variable_a, function_a<\/p>\n<p>print(variable_a)<\/p>\n<p>print(function_a())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>from file_a import variable_a, function_a<\/code>\u5c06<code>file_a.py<\/code>\u4e2d\u7684\u7279\u5b9a\u53d8\u91cf\u548c\u51fd\u6570\u5bfc\u5165\u5230<code>file_b.py<\/code>\u4e2d\u3002\u8fd9\u6837\uff0c\u6211\u4eec\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528<code>variable_a<\/code>\u548c<code>function_a()<\/code>\uff0c\u800c\u65e0\u9700\u524d\u7f00\u3002<\/p>\n<\/p>\n<p><h4>\u4f18\u70b9<\/h4>\n<\/p>\n<ol>\n<li><strong>\u7b80\u6d01<\/strong>\uff1a\u65e0\u9700\u4f7f\u7528\u6a21\u5757\u540d\u524d\u7f00\uff0c\u4ee3\u7801\u66f4\u7b80\u6d01\u3002<\/li>\n<li><strong>\u9009\u62e9\u6027\u5bfc\u5165<\/strong>\uff1a\u53ea\u5bfc\u5165\u6240\u9700\u7684\u5185\u5bb9\uff0c\u51cf\u5c11\u547d\u540d\u7a7a\u95f4\u6c61\u67d3\u3002<\/li>\n<\/ol>\n<p><h4>\u7f3a\u70b9<\/h4>\n<\/p>\n<ol>\n<li><strong>\u547d\u540d\u51b2\u7a81<\/strong>\uff1a\u5982\u679c\u5bfc\u5165\u7684\u53d8\u91cf\u6216\u51fd\u6570\u540d\u4e0e\u5f53\u524d\u6587\u4ef6\u4e2d\u7684\u5df2\u6709\u540d\u79f0\u51b2\u7a81\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u95ee\u9898\u3002<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u4f7f\u7528__init__.py\u6587\u4ef6\u7ba1\u7406\u5305<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u4e00\u4e2a\u76ee\u5f55\u5305\u542b\u4e00\u4e2a<code>__init__.py<\/code>\u6587\u4ef6\uff0c\u8fd9\u4e2a\u76ee\u5f55\u5c31\u4f1a\u88ab\u8ba4\u4e3a\u662f\u4e00\u4e2a\u5305\u3002\u901a\u8fc7\u4f7f\u7528<code>__init__.py<\/code>\u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u66f4\u597d\u5730\u7ec4\u7ec7\u548c\u7ba1\u7406\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>\u6587\u4ef6\u793a\u4f8b<\/h4>\n<\/p>\n<p><p><strong>project_structure<\/strong><\/p>\n<\/p>\n<p><pre><code>project\/<\/p>\n<p>    __init__.py<\/p>\n<p>    file_a.py<\/p>\n<p>    file_b.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>file_a.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_a.py<\/p>\n<p>variable_a = &quot;Hello from file_a!&quot;<\/p>\n<p>def function_a():<\/p>\n<p>    return &quot;This is function_a from file_a!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>file_b.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_b.py<\/p>\n<p>from project.file_a import variable_a, function_a<\/p>\n<p>print(variable_a)<\/p>\n<p>print(function_a())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5c06\u6587\u4ef6\u7ec4\u7ec7\u5728\u4e00\u4e2a\u5305\u4e2d\uff0c\u5e76\u4f7f\u7528<code>from project.file_a import variable_a, function_a<\/code>\u5bfc\u5165\u53d8\u91cf\u548c\u51fd\u6570\u3002\u8fd9\u6837\u53ef\u4ee5\u66f4\u597d\u5730\u7ec4\u7ec7\u4ee3\u7801\uff0c\u5c24\u5176\u662f\u5728\u5927\u578b\u9879\u76ee\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165<\/h3>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u5c24\u5176\u662f\u5728\u5305\u5185\u7684\u6a21\u5757\u4e4b\u95f4\u8fdb\u884c\u5bfc\u5165\u65f6\uff0c\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165\u4f1a\u66f4\u52a0\u65b9\u4fbf\u3002\u76f8\u5bf9\u5bfc\u5165\u4f7f\u7528\u70b9\uff08<code>.<\/code>\uff09\u8868\u793a\u5f53\u524d\u76ee\u5f55\u548c\u7236\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><h4>\u6587\u4ef6\u793a\u4f8b<\/h4>\n<\/p>\n<p><p><strong>project_structure<\/strong><\/p>\n<\/p>\n<p><pre><code>project\/<\/p>\n<p>    __init__.py<\/p>\n<p>    submodule\/<\/p>\n<p>        __init__.py<\/p>\n<p>        file_a.py<\/p>\n<p>        file_b.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>file_a.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_a.py<\/p>\n<p>variable_a = &quot;Hello from file_a!&quot;<\/p>\n<p>def function_a():<\/p>\n<p>    return &quot;This is function_a from file_a!&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>file_b.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_b.py<\/p>\n<p>from .file_a import variable_a, function_a<\/p>\n<p>print(variable_a)<\/p>\n<p>print(function_a())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>from .file_a import variable_a, function_a<\/code>\u8fdb\u884c\u76f8\u5bf9\u5bfc\u5165\uff0c\u8fd9\u6837\u53ef\u4ee5\u5728\u5305\u5185\u66f4\u65b9\u4fbf\u5730\u8fdb\u884c\u6a21\u5757\u95f4\u7684\u5bfc\u5165\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5904\u7406\u5bfc\u5165\u65f6\u7684\u5faa\u73af\u4f9d\u8d56\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5728\u590d\u6742\u9879\u76ee\u4e2d\uff0c\u6709\u65f6\u4f1a\u9047\u5230\u5faa\u73af\u4f9d\u8d56\u95ee\u9898\uff0c\u5373\u4e24\u4e2a\u6216\u591a\u4e2a\u6a21\u5757\u76f8\u4e92\u5bfc\u5165\u5bf9\u65b9\u7684\u5185\u5bb9\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u9700\u8981\u7279\u522b\u5c0f\u5fc3\uff0c\u4ee5\u907f\u514d\u5bfc\u5165\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h4>\u89e3\u51b3\u65b9\u6cd5<\/h4>\n<\/p>\n<ol>\n<li><strong>\u91cd\u6784\u4ee3\u7801<\/strong>\uff1a\u5c3d\u91cf\u907f\u514d\u5faa\u73af\u4f9d\u8d56\uff0c\u901a\u8fc7\u91cd\u6784\u4ee3\u7801\u5c06\u516c\u5171\u90e8\u5206\u62bd\u53d6\u5230\u4e00\u4e2a\u5355\u72ec\u7684\u6a21\u5757\u4e2d\u3002<\/li>\n<li><strong>\u5ef6\u8fdf\u5bfc\u5165<\/strong>\uff1a\u5728\u51fd\u6570\u6216\u65b9\u6cd5\u5185\u90e8\u8fdb\u884c\u5bfc\u5165\uff0c\u800c\u4e0d\u662f\u5728\u6a21\u5757\u9876\u5c42\u8fdb\u884c\u5bfc\u5165\u3002<\/li>\n<\/ol>\n<p><h4>\u793a\u4f8b<\/h4>\n<\/p>\n<p><p><strong>file_a.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_a.py<\/p>\n<p>def function_a():<\/p>\n<p>    from project.submodule.file_b import function_b<\/p>\n<p>    print(&quot;Function A&quot;)<\/p>\n<p>    function_b()<\/p>\n<p>function_a()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>file_b.py<\/strong><\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># file_b.py<\/p>\n<p>def function_b():<\/p>\n<p>    from project.submodule.file_a import function_a<\/p>\n<p>    print(&quot;Function B&quot;)<\/p>\n<p>    function_a()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c\u6211\u4eec\u5728\u51fd\u6570\u5185\u90e8\u8fdb\u884c\u5bfc\u5165\uff0c\u907f\u514d\u4e86\u6a21\u5757\u9876\u5c42\u7684\u5faa\u73af\u4f9d\u8d56\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u6709\u591a\u79cd\u65b9\u6cd5\u53ef\u4ee5\u5bfc\u5165\u53e6\u4e00\u4e2a\u6587\u4ef6\u7684\u53d8\u91cf\u548c\u51fd\u6570\uff0c\u5305\u62ec\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u3001<code>from...import<\/code>\u8bed\u53e5\u3001\u4f7f\u7528<code>__init__.py<\/code>\u6587\u4ef6\u7ba1\u7406\u5305\u3001\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165\uff0c\u4ee5\u53ca\u5904\u7406\u5bfc\u5165\u65f6\u7684\u5faa\u73af\u4f9d\u8d56\u95ee\u9898\u3002<strong>\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u53ef\u8bfb\u6027\u548c\u53ef\u7ef4\u62a4\u6027<\/strong>\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5e94\u7528\u8fd9\u4e9b\u6280\u672f\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u5bfc\u5165\u7279\u5b9a\u6587\u4ef6\u7684\u53d8\u91cf\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u6765\u5bfc\u5165\u53e6\u4e00\u4e2a\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u3002\u60a8\u9700\u8981\u786e\u4fdd\u76ee\u6807\u6587\u4ef6\u548c\u5f53\u524d\u6587\u4ef6\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\uff0c\u6216\u5728Python\u8def\u5f84\u4e2d\u3002\u4f7f\u7528<code>from &lt;filename&gt; import &lt;variable&gt;<\/code>\u8bed\u6cd5\uff0c\u53ef\u4ee5\u76f4\u63a5\u5bfc\u5165\u6240\u9700\u7684\u53d8\u91cf\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u7684\u6587\u4ef6\u540d\u4e3a<code>config.py<\/code>\uff0c\u5e76\u4e14\u60a8\u60f3\u5bfc\u5165\u5176\u4e2d\u7684<code>API_KEY<\/code>\u53d8\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528<code>from config import API_KEY<\/code>\u3002<\/p>\n<p><strong>\u5bfc\u5165\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u662f\u5426\u4f1a\u5f71\u54cd\u539f\u6587\u4ef6\u4e2d\u7684\u503c\uff1f<\/strong><br \/>\u5bfc\u5165\u53d8\u91cf\u4e0d\u4f1a\u5f71\u54cd\u539f\u6587\u4ef6\u4e2d\u7684\u503c\uff0c\u56e0\u4e3a\u5bfc\u5165\u7684\u662f\u53d8\u91cf\u7684\u526f\u672c\u3002\u5982\u679c\u60a8\u5728\u5bfc\u5165\u540e\u4fee\u6539\u4e86\u53d8\u91cf\u7684\u503c\uff0c\u8fd9\u4e00\u53d8\u5316\u4e0d\u4f1a\u53cd\u6620\u5230\u539f\u6587\u4ef6\u4e2d\u3002\u539f\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u59cb\u7ec8\u4fdd\u6301\u5176\u521d\u59cb\u503c\uff0c\u9664\u975e\u60a8\u5728\u539f\u6587\u4ef6\u4e2d\u663e\u5f0f\u66f4\u6539\u5b83\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u5bfc\u5165\u6a21\u5757\u65f6\u51fa\u73b0\u7684\u547d\u540d\u51b2\u7a81\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u5982\u679c\u5bfc\u5165\u7684\u53d8\u91cf\u4e0e\u5f53\u524d\u6587\u4ef6\u4e2d\u7684\u53d8\u91cf\u540c\u540d\uff0c\u5c31\u4f1a\u53d1\u751f\u547d\u540d\u51b2\u7a81\u3002\u4e3a\u4e86\u89e3\u51b3\u8fd9\u4e2a\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528\u522b\u540d\u3002\u901a\u8fc7<code>import &lt;filename&gt; as &lt;alias&gt;<\/code>\u8bed\u6cd5\uff0c\u60a8\u53ef\u4ee5\u4e3a\u6574\u4e2a\u6a21\u5757\u6307\u5b9a\u4e00\u4e2a\u522b\u540d\uff0c\u4ece\u800c\u907f\u514d\u51b2\u7a81\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>import config as cfg<\/code>\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7<code>cfg.API_KEY<\/code>\u6765\u8bbf\u95ee<code>config.py<\/code>\u4e2d\u7684<code>API_KEY<\/code>\uff0c\u800c\u4e0d\u662f\u76f4\u63a5\u4f7f\u7528<code>API_KEY<\/code>\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5bfc\u5165\u53e6\u4e00\u4e2a\u6587\u4ef6\u7684\u53d8\u91cf\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528import\u8bed\u53e5\u3001from&#8230;import\u8bed\u53e5 [&hellip;]","protected":false},"author":3,"featured_media":1139818,"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\/1139814"}],"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=1139814"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1139814\/revisions"}],"predecessor-version":[{"id":1139821,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1139814\/revisions\/1139821"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1139818"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1139814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1139814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1139814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}