{"id":1001897,"date":"2024-12-27T10:04:11","date_gmt":"2024-12-27T02:04:11","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1001897.html"},"modified":"2024-12-27T10:04:15","modified_gmt":"2024-12-27T02:04:15","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e7%bc%96%e5%86%99%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1001897.html","title":{"rendered":"\u5982\u4f55\u4f7f\u7528python\u7f16\u5199\u811a\u672c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25075852\/e42c40a8-8713-43d2-9084-bf502f244208.webp\" alt=\"\u5982\u4f55\u4f7f\u7528python\u7f16\u5199\u811a\u672c\" \/><\/p>\n<p><p> <strong>\u4f7f\u7528Python\u7f16\u5199\u811a\u672c\u7684\u57fa\u672c\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u7f16\u8f91\u5668\u3001\u7406\u89e3\u811a\u672c\u7684\u57fa\u672c\u7ed3\u6784\u3001\u5229\u7528Python\u7684\u5e93\u5b9e\u73b0\u529f\u80fd\u3001\u8fdb\u884c\u8c03\u8bd5\u4e0e\u6d4b\u8bd5\u3002<\/strong>\u5176\u4e2d\uff0c\u9009\u62e9\u5408\u9002\u7684\u7f16\u8f91\u5668\u662f\u4e00\u4e2a\u91cd\u8981\u7684\u8d77\u70b9\u3002\u9009\u62e9\u4e00\u4e2a\u9002\u5408\u7684\u7f16\u8f91\u5668\u53ef\u4ee5\u63d0\u9ad8\u7f16\u7801\u6548\u7387\uff0c\u63a8\u8350\u4f7f\u7528\u50cfPyCharm\u3001VS Code\u8fd9\u6837\u7684\u5de5\u5177\uff0c\u56e0\u4e3a\u5b83\u4eec\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u63d2\u4ef6\u652f\u6301\u548c\u8c03\u8bd5\u5de5\u5177\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u4e9b\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u9009\u62e9\u5408\u9002\u7684\u7f16\u8f91\u5668<\/p>\n<\/p>\n<p><p>\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u7f16\u8f91\u5668\u662f\u7f16\u5199Python\u811a\u672c\u7684\u7b2c\u4e00\u6b65\u3002\u7f16\u8f91\u5668\u4e0d\u4ec5\u4ec5\u662f\u4e00\u4e2a\u4ee3\u7801\u7f16\u5199\u5de5\u5177\uff0c\u5b83\u8fd8\u80fd\u5e2e\u52a9\u7a0b\u5e8f\u5458\u63d0\u9ad8\u6548\u7387\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>PyCharm<\/strong><br \/>PyCharm\u662f\u7531JetBr<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>ns\u5f00\u53d1\u7684\u4e00\u6b3e\u4e13\u4e1a\u7684Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3002\u5b83\u5177\u6709\u667a\u80fd\u4ee3\u7801\u8865\u5168\u3001\u4ee3\u7801\u5bfc\u822a\u3001\u9519\u8bef\u68c0\u67e5\u3001\u91cd\u6784\u7b49\u529f\u80fd\u3002PyCharm\u8fd8\u652f\u6301Django\u3001Flask\u7b49Web\u6846\u67b6\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u662f\u4e13\u4e1a\u5f00\u53d1\u8005\u7684\u9996\u9009\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>VS Code<\/strong><br \/>Visual Studio Code\u662f\u5fae\u8f6f\u63a8\u51fa\u7684\u8f7b\u91cf\u7ea7\u7f16\u8f91\u5668\uff0c\u5177\u6709\u4e30\u5bcc\u7684\u6269\u5c55\u63d2\u4ef6\u3002\u5b83\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\uff0c\u5e76\u4e14\u5177\u6709\u5f3a\u5927\u7684\u8c03\u8bd5\u529f\u80fd\u3002VS Code\u7684\u4f18\u52bf\u5728\u4e8e\u5b83\u7684\u8f7b\u91cf\u7ea7\u548c\u53ef\u6269\u5c55\u6027\uff0c\u9002\u5408\u9700\u8981\u591a\u8bed\u8a00\u5f00\u53d1\u7684\u7a0b\u5e8f\u5458\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>Jupyter Notebook<\/strong><br \/>\u5982\u679c\u4f60\u9700\u8981\u8fdb\u884c\u6570\u636e\u5206\u6790\u6216\u79d1\u5b66\u8ba1\u7b97\uff0cJupyter Notebook\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002\u5b83\u5141\u8bb8\u4f60\u5728\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u7684\u73af\u5883\u4e2d\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\uff0c\u652f\u6301\u53ef\u89c6\u5316\u6570\u636e\u548c\u5b9e\u65f6\u8c03\u8bd5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u7406\u89e3\u811a\u672c\u7684\u57fa\u672c\u7ed3\u6784<\/p>\n<\/p>\n<p><p>Python\u811a\u672c\u7684\u57fa\u672c\u7ed3\u6784\u901a\u5e38\u5305\u62ec\u5bfc\u5165\u5e93\u3001\u5b9a\u4e49\u51fd\u6570\u3001\u6267\u884c\u4ee3\u7801\u4e09\u4e2a\u90e8\u5206\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u5bfc\u5165\u5e93<\/strong><br \/>\u4f7f\u7528Python\u7f16\u5199\u811a\u672c\u65f6\uff0c\u901a\u5e38\u9700\u8981\u5bfc\u5165\u4e00\u4e9b\u6807\u51c6\u5e93\u6216\u7b2c\u4e09\u65b9\u5e93\u3002\u5bfc\u5165\u5e93\u7684\u76ee\u7684\u662f\u4e3a\u4e86\u4f7f\u7528Python\u4e2d\u5df2\u7ecf\u5b9e\u73b0\u7684\u529f\u80fd\uff0c\u907f\u514d\u91cd\u590d\u9020\u8f6e\u5b50\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>import sys<\/p>\n<p>import numpy as np<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u5b9a\u4e49\u51fd\u6570<\/strong><br \/>\u51fd\u6570\u662fPython\u811a\u672c\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\u3002\u901a\u8fc7\u5b9a\u4e49\u51fd\u6570\uff0c\u53ef\u4ee5\u63d0\u9ad8\u4ee3\u7801\u7684\u590d\u7528\u6027\u548c\u53ef\u8bfb\u6027\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    print(f&quot;Hello, {name}!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u6267\u884c\u4ee3\u7801<\/strong><br \/>\u5728\u811a\u672c\u7684\u6700\u540e\uff0c\u901a\u5e38\u4f1a\u6709\u4e00\u4e9b\u6267\u884c\u4ee3\u7801\u3002\u8fd9\u4e2a\u90e8\u5206\u901a\u5e38\u5305\u62ec\u8c03\u7528\u51fd\u6570\u3001\u8fdb\u884c\u8ba1\u7b97\u3001\u6253\u5370\u7ed3\u679c\u7b49\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">if __name__ == &quot;__main__&quot;:<\/p>\n<p>    greet(&quot;World&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e09\u3001\u5229\u7528Python\u7684\u5e93\u5b9e\u73b0\u529f\u80fd<\/p>\n<\/p>\n<p><p>Python\u62e5\u6709\u4e30\u5bcc\u7684\u6807\u51c6\u5e93\u548c\u7b2c\u4e09\u65b9\u5e93\uff0c\u8fd9\u4f7f\u5f97Python\u5728\u7f16\u5199\u811a\u672c\u65f6\u975e\u5e38\u9ad8\u6548\u3002<\/p>\n<\/p>\n<ol>\n<li><strong>\u6807\u51c6\u5e93<\/strong><br \/>Python\u6807\u51c6\u5e93\u63d0\u4f9b\u4e86\u8bb8\u591a\u5b9e\u7528\u7684\u6a21\u5757\u548c\u51fd\u6570\u3002\u6bd4\u5982\uff0c<code>os<\/code>\u6a21\u5757\u53ef\u4ee5\u7528\u4e8e\u6587\u4ef6\u548c\u76ee\u5f55\u64cd\u4f5c\uff0c<code>sys<\/code>\u6a21\u5757\u53ef\u4ee5\u7528\u4e8e\u547d\u4ee4\u884c\u53c2\u6570\u89e3\u6790\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import os<\/p>\n<h2><strong>\u83b7\u53d6\u5f53\u524d\u5de5\u4f5c\u76ee\u5f55<\/strong><\/h2>\n<p>cwd = os.getcwd()<\/p>\n<p>print(&quot;Current working directory:&quot;, cwd)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7b2c\u4e09\u65b9\u5e93<\/strong><br \/>Python\u7684\u7b2c\u4e09\u65b9\u5e93\u6db5\u76d6\u4e86\u5404\u4e2a\u9886\u57df\uff0c\u5982\u6570\u636e\u5206\u6790\u3001<a href=\"https:\/\/docs.pingcode.com\/ask\/59192.html\" target=\"_blank\">\u673a\u5668\u5b66\u4e60<\/a>\u3001Web\u5f00\u53d1\u7b49\u3002\u5e38\u7528\u7684\u7b2c\u4e09\u65b9\u5e93\u6709<code>numpy<\/code>\u3001<code>pandas<\/code>\u3001<code>requests<\/code>\u7b49\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4<\/strong><\/h2>\n<p>arr = np.array([1, 2, 3, 4])<\/p>\n<p>print(&quot;Array:&quot;, arr)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u5b89\u88c5\u7b2c\u4e09\u65b9\u5e93<\/strong><br \/>\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\u524d\u9700\u8981\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7Python\u7684\u5305\u7ba1\u7406\u5de5\u5177<code>pip<\/code>\u8fdb\u884c\u5b89\u88c5\u3002<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">pip install numpy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u56db\u3001\u8fdb\u884c\u8c03\u8bd5\u4e0e\u6d4b\u8bd5<\/p>\n<\/p>\n<p><p>\u5728\u7f16\u5199\u5b8c\u811a\u672c\u540e\uff0c\u8c03\u8bd5\u548c\u6d4b\u8bd5\u662f\u975e\u5e38\u91cd\u8981\u7684\u6b65\u9aa4\uff0c\u4ee5\u786e\u4fdd\u811a\u672c\u7684\u6b63\u786e\u6027\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8c03\u8bd5<\/strong><br \/>\u8c03\u8bd5\u662f\u4e3a\u4e86\u627e\u51fa\u548c\u4fee\u590d\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u3002\u53ef\u4ee5\u4f7f\u7528IDE\u81ea\u5e26\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u4f8b\u5982PyCharm\u548cVS Code\u90fd\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u8c03\u8bd5\u529f\u80fd\u3002\u901a\u8fc7\u8bbe\u7f6e\u65ad\u70b9\u3001\u5355\u6b65\u6267\u884c\u548c\u68c0\u67e5\u53d8\u91cf\u503c\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u53d1\u73b0\u95ee\u9898\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6d4b\u8bd5<\/strong><br \/>\u6d4b\u8bd5\u662f\u4e3a\u4e86\u9a8c\u8bc1\u4ee3\u7801\u7684\u529f\u80fd\u662f\u5426\u7b26\u5408\u9884\u671f\u3002\u53ef\u4ee5\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\u6765\u81ea\u52a8\u5316\u6d4b\u8bd5\u8fc7\u7a0b\uff0cPython\u7684<code>unittest<\/code>\u6a21\u5757\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6d4b\u8bd5\u6846\u67b6\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>def add(x, y):<\/p>\n<p>    return x + y<\/p>\n<p>class TestMathOperations(unittest.TestCase):<\/p>\n<p>    def test_add(self):<\/p>\n<p>        self.assertEqual(add(2, 3), 5)<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u4ee3\u7801\u4f18\u5316<\/strong><br \/>\u5728\u8c03\u8bd5\u548c\u6d4b\u8bd5\u5b8c\u6210\u540e\uff0c\u4ee3\u7801\u4f18\u5316\u662f\u63d0\u9ad8\u4ee3\u7801\u6027\u80fd\u548c\u53ef\u8bfb\u6027\u7684\u91cd\u8981\u6b65\u9aa4\u3002\u53ef\u4ee5\u901a\u8fc7\u51cf\u5c11\u5197\u4f59\u4ee3\u7801\u3001\u4f7f\u7528\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u6765\u4f18\u5316\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u7f16\u5199\u5b9e\u7528\u7684Python\u811a\u672c\u6848\u4f8b<\/p>\n<\/p>\n<p><p>\u5728\u4e86\u89e3\u4e86Python\u811a\u672c\u7684\u57fa\u672c\u6b65\u9aa4\u548c\u7ed3\u6784\u540e\uff0c\u4e0b\u9762\u901a\u8fc7\u4e00\u4e2a\u5177\u4f53\u7684\u6848\u4f8b\u6765\u5c55\u793a\u5982\u4f55\u7f16\u5199\u4e00\u4e2a\u5b9e\u7528\u7684Python\u811a\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u6848\u4f8b\u63cf\u8ff0<\/strong><br \/>\u6211\u4eec\u5c06\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684Web\u722c\u866b\u811a\u672c\uff0c\u6293\u53d6\u4e00\u4e2a\u7f51\u7ad9\u7684\u6807\u9898\u548c\u63cf\u8ff0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b9e\u73b0\u6b65\u9aa4<\/strong><\/p>\n<\/p>\n<\/li>\n<\/ol>\n<ul>\n<li>\u5b89\u88c5\u5fc5\u8981\u7684\u5e93\uff1a<code>requests<\/code>\u548c<code>BeautifulSoup<\/code><\/li>\n<li>\u7f16\u5199\u811a\u672c\uff1a\u5bfc\u5165\u5e93\u3001\u5b9a\u4e49\u51fd\u6570\u3001\u5b9e\u73b0\u6293\u53d6\u529f\u80fd<\/li>\n<li>\u8c03\u8bd5\u4e0e\u6d4b\u8bd5\uff1a\u786e\u4fdd\u811a\u672c\u80fd\u591f\u6b63\u786e\u6293\u53d6\u4fe1\u606f<\/li>\n<\/ul>\n<ol start=\"3\">\n<li><strong>\u4ee3\u7801\u5b9e\u73b0<\/strong><\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>from bs4 import BeautifulSoup<\/p>\n<p>def fetch_website_info(url):<\/p>\n<p>    response = requests.get(url)<\/p>\n<p>    if response.status_code == 200:<\/p>\n<p>        soup = BeautifulSoup(response.content, &#39;html.parser&#39;)<\/p>\n<p>        title = soup.find(&#39;title&#39;).get_text()<\/p>\n<p>        description = soup.find(&#39;meta&#39;, attrs={&#39;name&#39;: &#39;description&#39;})[&#39;content&#39;]<\/p>\n<p>        return title, description<\/p>\n<p>    else:<\/p>\n<p>        return None, None<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    url = &quot;https:\/\/www.example.com&quot;<\/p>\n<p>    title, description = fetch_website_info(url)<\/p>\n<p>    if title and description:<\/p>\n<p>        print(&quot;Title:&quot;, title)<\/p>\n<p>        print(&quot;Description:&quot;, description)<\/p>\n<p>    else:<\/p>\n<p>        print(&quot;Failed to retrieve information.&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"4\">\n<li><strong>\u8c03\u8bd5\u4e0e\u6d4b\u8bd5<\/strong><\/li>\n<\/ol>\n<ul>\n<li>\u8c03\u8bd5\uff1a\u901a\u8fc7\u5728<code>fetch_website_info<\/code>\u51fd\u6570\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u68c0\u67e5<code>response<\/code>\u5bf9\u8c61\u7684\u72b6\u6001\u7801\u548c\u5185\u5bb9\u3002<\/li>\n<li>\u6d4b\u8bd5\uff1a\u66f4\u6362\u4e0d\u540c\u7684\u7f51\u7ad9URL\uff0c\u9a8c\u8bc1\u811a\u672c\u80fd\u5426\u6b63\u786e\u6293\u53d6\u6807\u9898\u548c\u63cf\u8ff0\u3002<\/li>\n<\/ul>\n<ol start=\"5\">\n<li><strong>\u4f18\u5316\u4e0e\u6269\u5c55<\/strong><\/li>\n<\/ol>\n<ul>\n<li>\u4f18\u5316\uff1a\u4f7f\u7528<code>try-except<\/code>\u5757\u5904\u7406\u5f02\u5e38\u60c5\u51b5\uff0c\u589e\u5f3a\u811a\u672c\u7684\u7a33\u5b9a\u6027\u3002<\/li>\n<li>\u6269\u5c55\uff1a\u53ef\u4ee5\u5c06\u6293\u53d6\u7ed3\u679c\u4fdd\u5b58\u5230\u6587\u4ef6\u4e2d\uff0c\u6216\u8fdb\u4e00\u6b65\u5206\u6790\u548c\u5904\u7406\u6293\u53d6\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u7f16\u5199\u51fa\u4e00\u4e2a\u529f\u80fd\u5b8c\u6574\u7684Python\u811a\u672c\u3002\u5728\u7f16\u5199Python\u811a\u672c\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684\u7f16\u8f91\u5668\u3001\u7406\u89e3\u811a\u672c\u7684\u7ed3\u6784\u3001\u5229\u7528Python\u7684\u5e93\u3001\u8fdb\u884c\u8c03\u8bd5\u4e0e\u6d4b\u8bd5\u662f\u63d0\u9ad8\u6548\u7387\u548c\u8d28\u91cf\u7684\u5173\u952e\u3002\u5e0c\u671b\u672c\u6587\u80fd\u591f\u4e3a\u4f60\u63d0\u4f9b\u6709\u4ef7\u503c\u7684\u53c2\u8003\u548c\u6307\u5bfc\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5f00\u59cb\u4f7f\u7528Python\u7f16\u5199\u811a\u672c\uff1f<\/strong><br \/>\u8981\u5f00\u59cb\u4f7f\u7528Python\u7f16\u5199\u811a\u672c\uff0c\u60a8\u9700\u8981\u5b89\u88c5Python\u89e3\u91ca\u5668\u3002\u53ef\u4ee5\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u6700\u65b0\u7248\u672c\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u4e00\u4e2a\u5408\u9002\u7684\u6587\u672c\u7f16\u8f91\u5668\u6216\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff0c\u5982PyCharm\u3001VS Code\u6216Jupyter Notebook\u3002\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6587\u672c\u6587\u4ef6\uff0c\u5c06\u5176\u547d\u540d\u4e3a\u4ee5\u201c.py\u201d\u7ed3\u5c3e\u7684\u6587\u4ef6\uff0c\u4f8b\u5982\u201cscript.py\u201d\uff0c\u7136\u540e\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u60a8\u7684Python\u4ee3\u7801\u3002\u901a\u8fc7\u547d\u4ee4\u884c\u6216\u7ec8\u7aef\u8fd0\u884c\u8be5\u811a\u672c\uff0c\u53ea\u9700\u8f93\u5165<code>python script.py<\/code>\u5373\u53ef\u3002<\/p>\n<p><strong>\u5728Python\u811a\u672c\u4e2d\u5982\u4f55\u5bfc\u5165\u5e93\u548c\u6a21\u5757\uff1f<\/strong><br \/>\u5728Python\u811a\u672c\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>import<\/code>\u8bed\u53e5\u6765\u5bfc\u5165\u5e93\u548c\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u60f3\u4f7f\u7528NumPy\u5e93\uff0c\u53ef\u4ee5\u5728\u811a\u672c\u7684\u5f00\u5934\u6dfb\u52a0<code>import numpy as np<\/code>\u3002\u8fd9\u5c06\u5141\u8bb8\u60a8\u4f7f\u7528NumPy\u5e93\u4e2d\u7684\u529f\u80fd\u3002\u786e\u4fdd\u5728\u8fd0\u884c\u811a\u672c\u4e4b\u524d\u5df2\u7ecf\u5b89\u88c5\u6240\u9700\u7684\u5e93\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>pip install library_name<\/code>\u547d\u4ee4\u6765\u5b89\u88c5\u3002<\/p>\n<p><strong>\u5982\u4f55\u8c03\u8bd5Python\u811a\u672c\u4ee5\u6392\u67e5\u9519\u8bef\uff1f<\/strong><br \/>\u8c03\u8bd5Python\u811a\u672c\u7684\u6709\u6548\u65b9\u6cd5\u5305\u62ec\u4f7f\u7528<code>print()<\/code>\u51fd\u6570\u8f93\u51fa\u53d8\u91cf\u7684\u503c\uff0c\u5e2e\u52a9\u60a8\u7406\u89e3\u4ee3\u7801\u6267\u884c\u8fc7\u7a0b\u3002\u6b64\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u5185\u7f6e\u7684\u8c03\u8bd5\u5de5\u5177<code>pdb<\/code>\uff0c\u901a\u8fc7\u5728\u811a\u672c\u4e2d\u63d2\u5165<code>import pdb; pdb.set_trace()<\/code>\u6765\u8bbe\u7f6e\u65ad\u70b9\uff0c\u4ece\u800c\u9010\u884c\u6267\u884c\u4ee3\u7801\uff0c\u67e5\u770b\u6bcf\u4e00\u6b65\u7684\u72b6\u6001\u3002\u8bb8\u591aIDE\u4e5f\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u8c03\u8bd5\u529f\u80fd\uff0c\u5141\u8bb8\u60a8\u5728\u56fe\u5f62\u754c\u9762\u4e2d\u8bbe\u7f6e\u65ad\u70b9\u3001\u76d1\u89c6\u53d8\u91cf\u548c\u6267\u884c\u4ee3\u7801\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4f7f\u7528Python\u7f16\u5199\u811a\u672c\u7684\u57fa\u672c\u6b65\u9aa4\u5305\u62ec\uff1a\u9009\u62e9\u5408\u9002\u7684\u7f16\u8f91\u5668\u3001\u7406\u89e3\u811a\u672c\u7684\u57fa\u672c\u7ed3\u6784\u3001\u5229\u7528Python\u7684\u5e93\u5b9e\u73b0\u529f\u80fd\u3001\u8fdb [&hellip;]","protected":false},"author":3,"featured_media":1001911,"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\/1001897"}],"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=1001897"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001897\/revisions"}],"predecessor-version":[{"id":1001916,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1001897\/revisions\/1001916"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1001911"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1001897"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1001897"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1001897"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}