{"id":275,"date":"2023-10-27T09:57:55","date_gmt":"2023-10-27T01:57:55","guid":{"rendered":"http:\/\/ai.gitpp.com\/?p=275"},"modified":"2023-10-31T14:51:16","modified_gmt":"2023-10-31T06:51:16","slug":"%e3%80%8apython%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b%e3%80%8b6-%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/27\/%e3%80%8apython%e5%85%a5%e9%97%a8%e6%95%99%e7%a8%8b%e3%80%8b6-%e6%a8%a1%e5%9d%97\/","title":{"rendered":"\u300aPython\u5165\u95e8\u6559\u7a0b\u300b6. \u6a21\u5757"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5f00\u80c3\u83dc<\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/2-%e4%bd%bf%e7%94%a8-python-%e8%a7%a3%e9%87%8a%e5%99%a8\/\">\u4f7f\u7528 Python \u89e3\u91ca\u5668<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/3-%e9%9d%9e%e6%ad%a3%e5%bc%8f%e4%bb%8b%e7%bb%8dpython\/\">\u975e\u6b63\u5f0f\u4ecb\u7ecdPython<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/4-%e6%b7%b1%e5%85%a5%e6%b5%81%e7%a8%8b%e6%8e%a7%e5%88%b6\/\">\u6df1\u5165\u6d41\u7a0b\u63a7\u5236<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/5-%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84\/\">\u6570\u636e\u7ed3\u6784<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/6-%e6%a8%a1%e5%9d%97\/\">\u6a21\u5757<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/7-%e8%be%93%e5%85%a5%e5%92%8c%e8%be%93%e5%87%ba\/\">\u8f93\u5165\u548c\u8f93\u51fa<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/8-%e9%94%99%e8%af%af%e5%92%8c%e5%bc%82%e5%b8%b8\/\">\u9519\u8bef\u548c\u5f02\u5e38<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/9-%e7%b1%bb\/\">\u7c7b<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/10-%e6%a0%87%e5%87%86%e5%ba%93%e7%9a%84%e7%ae%80%e6%98%8e%e4%bb%8b%e7%bb%8d\/\">\u6807\u51c6\u5e93\u7684\u7b80\u660e\u4ecb\u7ecd<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/11-%e6%a0%87%e5%87%86%e5%ba%93%e7%9a%84%e7%ae%80%e6%98%8e%e4%bb%8b%e7%bb%8d%ef%bc%88%e7%ac%ac%e4%ba%8c%e9%83%a8%e5%88%86%ef%bc%89\/\">\u6807\u51c6\u5e93\u7684\u7b80\u660e\u4ecb\u7ecd\uff08\u7b2c\u4e8c\u90e8\u5206\uff09<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/12-%e7%8e%b0%e5%9c%a8%e5%b9%b2%e4%bb%80%e4%b9%88\/\">\u73b0\u5728\u5e72\u4ec0\u4e48?<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/13-%e4%ba%a4%e4%ba%92%e5%bc%8f%e8%be%93%e5%85%a5%e7%bc%96%e8%be%91%e5%8f%8a%e5%8e%86%e5%8f%b2%e6%9b%bf%e4%bb%a3\/\">\u4ea4\u4e92\u5f0f\u8f93\u5165\u7f16\u8f91\u53ca\u5386\u53f2\u66ff\u4ee3<\/a><\/li>\n\n\n\n<li><a href=\"http:\/\/ai.gitpp.com\/index.php\/2023\/10\/26\/14-%e6%b5%ae%e7%82%b9%e7%ae%97%e6%9c%af-%e9%97%ae%e9%a2%98%e5%92%8c%e9%99%90%e5%88%b6\/\">\u6d6e\u70b9\u7b97\u672f: \u95ee\u9898\u548c\u9650\u5236<\/a><\/li>\n<\/ol>\n\n\n\n<p>\u5982\u679c\u4f60\u4ece Python \u89e3\u91ca\u5668\u9000\u51fa\u540e\u518d\u91cd\u65b0\u8fdb\u5165, \u90a3\u4e48\u4f60\u4e4b\u524d\u5b9a\u4e49\u7684\u6240\u6709 (\u51fd\u5f0f\u548c\u53d8\u91cf) \u90fd\u5c06\u4e22\u5931. \u56e0\u6b64, \u5982\u679c\u4f60\u60f3\u5199\u4e00\u4e2a\u66f4\u957f\u7684\u7a0b\u5e8f, \u4f60\u6700\u597d\u79bb\u7ebf\u5730\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u4fdd\u5b58\u6210\u6587\u4ef6,\u66ff\u4ee3\u89e3\u91ca\u5668\u7684\u8f93\u5165\u6765\u8fd0\u884c. \u8fd9\u79f0\u4f5c\u521b\u5efa\u4e00\u4e2a&nbsp;<em>\u811a\u672c<\/em>&nbsp;. \u5f53\u4f60\u7684\u7a0b\u5e8f\u53d8\u5f97\u66f4\u957f, \u4f60\u53ef\u80fd\u60f3\u628a\u5b83\u5206\u5272\u6210\u51e0\u4e2a\u6587\u4ef6\u4ee5\u80fd\u591f\u66f4\u7b80\u5355\u5730\u7ef4\u62a4. \u4f60\u4e5f\u8bb8\u8fd8\u60f3\u5728\u51e0\u4e2a\u4e0b\u540c\u7684\u7a0b\u5e8f\u91cc\u4f7f\u7528\u5199\u8fc7\u7684\u7a0b\u5e8f, \u800c\u4e0d\u7528\u628a\u4e00\u5768\u4ee3\u7801\u62f7\u6765\u62f7\u53bb.<\/p>\n\n\n\n<p>\u4e3a\u6b64 Python \u63d0\u4f9b\u4e86\u65b9\u6cd5, \u80fd\u4f7f\u7528\u6237\u628a\u5b9a\u4e49\u5b58\u653e\u5728\u6587\u4ef6\u91cc, \u540c\u65f6\u53c8\u80fd\u5728\u811a\u672c\u6216\u4ea4\u4e92\u5f0f\u73af\u5883\u4e0b\u65b9\u4fbf\u7684\u4f7f\u7528\u5b83\u4eec. \u8fd9\u6837\u7684\u6587\u4ef6\u79f0\u4e3a&nbsp;<code>\u6a21\u5757<\/code>&nbsp;; \u4e00\u4e2a&nbsp;<code>\u6a21\u5757<\/code>&nbsp;\u4e2d\u7684\u5b9a\u4e49\u53ef\u4ee5&nbsp;<code>\u5bfc\u5165(import)<\/code>&nbsp;\u5230\u53e6\u4e00\u4e2a\u6a21\u5757\u6216&nbsp;<em>\u4e3b<\/em>&nbsp;\u6a21\u5757 (&nbsp;<em>\u4e3b<\/em>&nbsp;\u6a21\u5757\u662f\u6267\u884c\u811a\u672c\u7684\u6700\u4e0a\u5c42\u6216\u8ba1\u7b97\u6a21\u5f0f\u4e0b\u7684\u4e00\u7ec4\u53ef\u8bbf\u95ee\u53d8\u91cf\u7684\u96c6\u5408).<\/p>\n\n\n\n<p>\u6a21\u5757\u5c31\u662f\u5305\u542b Python \u5b9a\u4e49\u548c\u8bed\u53e5\u7684\u6587\u4ef6. \u6587\u4ef6\u7684\u540d\u5b57\u5c31\u662f\u8fd9\u4e2a\u6a21\u5757\u540d\u518d\u52a0\u4e0a\u00a0<code>.py<\/code>. \u5728\u4e00\u4e2a\u6a21\u5757\u4e2d, \u6a21\u5757\u7684\u540d\u5b57 (\u4e00\u4e2a\u5b57\u7b26\u4e32) \u53ef\u4ee5\u901a\u8fc7\u5168\u5c40\u53d8\u91cf\u00a0<code>__name__<\/code>\u00a0\u5f97\u5230. \u4f8b\u5982, \u4f7f\u7528\u4f60\u6700\u559c\u6b22\u7684\u6587\u6863\u7f16\u8f91\u5668\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a\u00a0<code>fibo.py<\/code>\u00a0\u7684\u6587\u4ef6, \u5e76\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><em># Fibonacci \u6570\u5217\u6a21\u5757<\/em><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>def<\/strong>\u00a0fib(n):\u00a0<em># \u6253\u5370\u5c0f\u4e8e n \u7684 Fibonacci \u6570\u5217<\/em>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">a, b = 0, 1\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>while<\/strong>\u00a0b &lt; n: <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">print(b, end=\u2019 \u2018) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">a, b = b, a+b<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> print()<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>def<\/strong>\u00a0fib2(n):\u00a0<em># \u8fd4\u56de\u5c0f\u4e8e n \u7684 Fibonacci \u6570\u5217<\/em>\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">result = [] <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">a, b = 0, 1<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>while<\/strong>\u00a0b &lt; n:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> result.append(b)<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> a, b = b, a+b\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>return<\/strong>\u00a0result<\/p>\n\n\n\n<p>\u73b0\u5728\u6253\u5f00 Python \u89e3\u91ca\u5668\u5e76\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u00a0<code>\u5bfc\u5165(import)<\/code>\u00a0\u8fd9\u4e2a\u6a21\u5757:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0importfibo<\/strong><\/p>\n\n\n\n<p>\u8fd9\u6837\u5e76\u4e0d\u4f1a\u628a\u00a0<code>fibo<\/code>\u00a0\u4e2d\u5b9a\u4e49\u7684\u51fd\u5f0f\u540d\u00a0<code>\u5bfc\u5165(import)<\/code>\u00a0\u5230\u5f53\u524d\u7684\u7b26\u53f7\u8868\u91cc; \u5b83\u53ea\u5bfc\u5165\u4e86\u6a21\u5757\u540d\u00a0<code>fibo<\/code>. \u4f60\u53ef\u4ee5\u4f7f\u7528\u6a21\u5757\u540d\u6765\u8bbf\u95ee\u51fd\u5f0f:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>fibo.fib(1000) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>fibo.fib2(100) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>fibo.__name__ <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u2018fibo\u2019<\/p>\n\n\n\n<p>\u5982\u679c\u4f60\u8981\u7ecf\u5e38\u4f7f\u7528\u4e00\u4e2a\u51fd\u5f0f\u7684\u8bdd, \u53ef\u4ee5\u628a\u5b83\u8d4b\u7ed9\u4e00\u4e2a\u5c40\u90e8\u53d8\u91cf:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>fib = fibo.fib\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>fib(500) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">1 1 2 3 5 8 13 21 34 55 89 144 233 377<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6.1. \u6df1\u5165\u6a21\u5757<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#tut-moremodules\"><\/a><\/h2>\n\n\n\n<p>\u6a21\u5757\u4e0d\u4ec5\u5305\u542b\u51fd\u5f0f\u5b9a\u4e49, \u8fd8\u53ef\u4ee5\u5305\u542b\u53ef\u6267\u884c\u7684\u8bed\u53e5. \u8fd9\u4e9b\u8bed\u53e5\u4e00\u822c\u7528\u4ee5\u521d\u59cb\u5316\u6a21\u5757. \u4ed6\u4eec\u4ec5\u5728\u6a21\u5757&nbsp;<em>\u7b2c\u4e00<\/em>&nbsp;\u6b21\u88ab\u5bfc\u5165\u65f6\u624d\u88ab\u6267\u884c.&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#id18\">[1]<\/a><\/p>\n\n\n\n<p>\u6bcf\u4e2a\u6a21\u5757\u6709\u5176\u79c1\u6709\u7684\u7b26\u53f7\u8868, \u7531\u6a21\u5757\u5185\u90e8\u5b9a\u4e49\u7684\u51fd\u5f0f\u5f53\u6210\u5168\u5c40\u7b26\u53f7\u8868\u6765\u4f7f\u7528. \u56e0\u6b64, \u6a21\u5757\u7684\u4f5c\u8005\u53ef\u4ee5\u5728\u6a21\u5757\u4e2d\u653e\u80c6\u4f7f\u7528\u5168\u5c40\u53d8\u91cf\u800c\u65e0\u9700\u62c5\u5fc3\u4e0e\u7528\u6237\u7684\u5168\u5c40\u53d8\u91cf\u53d1\u751f\u51b2\u7a81. \u53e6\u4e00\u65b9\u9762, \u5f53\u4f60\u786e\u5b9e\u660e\u767d\u4f60\u5728\u505a\u4ec0\u4e48\u7684\u65f6\u5019, \u4f60\u53ef\u4ee5 \u901a\u8fc7&nbsp;modname.itemname&nbsp;\u5f62\u5f0f\u6765\u8bbf\u95ee\u6a21\u5757\u7684\u5168\u5c40\u53d8\u91cf.<\/p>\n\n\n\n<p>\u6a21\u5757\u4e2d\u53ef\u4ee5\u5bfc\u5165\u5176\u5b83\u7684\u6a21\u5757. \u4e60\u60ef\u4e0a\u628a&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#import\"><code>import<\/code><\/a>&nbsp;\u8bed\u53e5\u653e\u5728\u4e00\u4e2a\u6a21\u5757 (\u6216\u8005\u811a\u672c, ) \u7684\u6700\u5f00\u59cb, \u5f53\u7136\u8fd9\u53ea\u662f\u60ef\u4f8b\u4e0d\u662f\u5f3a\u5236\u7684. \u88ab\u5bfc\u5165\u6a21\u5757\u7684\u540d\u79f0\u88ab\u653e\u5165\u5f53\u524d\u6a21\u5757\u7684\u5168\u5c40\u7b26\u53f7\u8868\u91cc.<\/p>\n\n\n\n<p><a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#import\"><code>import<\/code><\/a>\u00a0\u8bed\u53e5\u8fd9\u6709\u4e00\u79cd\u4e0d\u540c\u7528\u6cd5, \u5b83\u53ef\u4ee5\u76f4\u63a5\u628a\u4e00\u4e2a\u6a21\u5757\u5185(\u51fd\u5f0f,\u53d8\u91cf)\u540d\u79f0\u5bfc\u5165\u5f53\u524d\u6a21\u5757\u7b26\u53f7\u8868\u91cc. \u4f8b\u5982:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0fromfiboimport<\/strong>\u00a0fib, fib2\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>fib(500)<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> 1 1 2 3 5 8 13 21 34 55 89 144 233 377<\/p>\n\n\n\n<p>\u8fd9\u6837\u4e0d\u4f1a\u5bfc\u5165\u76f8\u5e94\u7684\u6a21\u5757\u540d (\u5728\u8fd9\u4e2a\u4f8b\u5b50\u91cc,&nbsp;<code>fibo<\/code>&nbsp;\u5e76\u6ca1\u6709\u88ab\u5b9a\u4e49).<\/p>\n\n\n\n<p>\u8fd8\u6709\u4e00\u79cd\u65b9\u6cd5\u53ef\u4e00\u6b21\u6027\u5bfc\u5165\u6a21\u5757\u4e2d\u6240\u6709\u7684\u540d\u5b57\u5b9a\u4e49:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0fromfiboimport<\/strong>\u00a0*\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>fib(500) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">1 1 2 3 5 8 13 21 34 55 89 144 233 377<\/p>\n\n\n\n<p>\u8fd9\u6837\u53ef\u4ee5\u5bfc\u5165\u9664\u4ee5\u4e0b\u5212\u7ebf\u5f00\u5934 (<code>_<\/code>) \u7684\u6240\u6709\u540d\u5b57. \u591a\u6570\u60c5\u51b5\u4e2d, Python \u7a0b\u5e8f\u5458\u4e0d\u4f7f\u7528\u8fd9\u4e2a\u7a8d\u95e8, \u56e0\u4e3a\u5b83\u5bfc\u5165\u4e86\u4e00\u4e9b\u672a\u77e5\u7684\u540d\u5b57\u5230\u89e3\u91ca\u5668\u91cc, \u56e0\u6b64\u53ef\u80fd\u4f1a\u610f\u5916\u91cd\u8f7d\u4e00\u4e9b\u4f60\u5df2\u7ecf\u5b9a\u4e49\u7684\u4e1c\u897f.<\/p>\n\n\n\n<p>\u6ce8\u610f: \u5728\u4e00\u822c\u7684\u5b9e\u8df5\u4e2d, \u5bfc\u5165&nbsp;<code>*<\/code>&nbsp;\u662f\u4e0d\u597d\u7684, \u56e0\u4e3a\u5b83\u5e38\u5e38\u4ea7\u751f\u96be\u4ee5\u9605\u8bfb\u7684\u4ee3\u7801. \u7136\u800c, \u5728\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u4f1a\u8bdd\u91cc\u4f7f\u7528\u5b83\u53ef\u4ee5\u8282\u7701\u952e\u5165.<\/p>\n\n\n\n<p><strong>Note\u00a0\uff1a\u56e0\u4e3a\u6548\u7387\u7684\u539f\u56e0, \u6bcf\u4e2a\u6a21\u5757\u5728\u6bcf\u4e2a\u89e3\u91ca\u5668\u4f1a\u8bdd\u4e2d\u53ea\u88ab\u5bfc\u5165\u4e00\u6b21. \u4e00\u65e6\u4f60\u4fee\u8ba2\u4e86\u4f60\u7684\u6a21\u5757, \u5c31\u9700\u8981\u91cd\u542f\u89e3\u91ca\u5668 \u2014- \u6216\u8005, \u82e5\u4f60\u53ea\u662f\u60f3\u4ea4\u4e92\u5f0f\u5730\u6d4b\u8bd5\u4e00\u4e2a\u6a21\u5757, \u4f7f\u7528\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/imp.html#imp.reload\"><code>imp.reload()<\/code><\/a>, \u4f8b\u5982\u00a0<code>import\u00a0imp;\u00a0imp.reload(modulename)<\/code>.<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.1.1. \u628a\u6a21\u5757\u5f53\u811a\u672c\u6267\u884c<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#tut-modulesasscripts\"><\/a><\/h3>\n\n\n\n<p>\u5f53\u4f60\u4ee5\u5982\u4e0b\u65b9\u5f0f\u8fd0\u884c\u4e00\u4e2a Python \u6a21\u5757\u65f6<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">python fibo.py &lt;arguments><\/p>\n\n\n\n<p>\u6a21\u5757\u4e2d\u7684\u4ee3\u7801\u5c31\u4f1a\u88ab\u6267\u884c, \u5c31\u50cf\u88ab\u5bfc\u5165\u65f6\u4e00\u6837, \u4f46\u00a0<code>__name__<\/code>\u00a0\u88ab\u8bbe\u4e3a\u00a0<code>\"__main__\"<\/code>\u00a0. \u8fd9\u5c31\u610f\u5473\u7740\u901a\u8fc7\u5728\u6a21\u5757\u6700\u540e\u52a0\u5165\u4ee5\u4e0b\u4ee3\u7801:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>if<\/strong>\u00a0__name__ == \u201c__main__\u201d:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>importsys<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0fib(int(sys.argv[1]))<\/p>\n\n\n\n<p>\u5c31\u80fd\u591f\u628a\u8fd9\u4e2a\u6587\u4ef6\u65e2\u5f53\u6210\u811a\u672c\u4f7f\u7528, \u4e5f\u53ef\u4ee5\u5f53\u6210\u53ef\u5bfc\u5165\u7684\u6a21\u5757\u4f7f\u7528, \u56e0\u4e3a\u89e3\u6790\u547d\u4ee4\u884c\u7684\u4ee3\u7801\u53ea\u5f53\u6a21\u5757\u88ab\u5f53\u6210 \u201c\u4e3b(main)\u201d \u65f6\u624d\u88ab\u76f4\u63a5\u8fd0\u884c:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">$ python fibo.py 50<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> 1 1 2 3 5 8 13 21 34<\/p>\n\n\n\n<p>\u5982\u679c\u6a21\u5757\u88ab\u5bfc\u5165, \u8fd9\u6bb5\u4ee3\u7801\u5e76\u4e0d\u6267\u884c:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0importfibo<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0>>><\/p>\n\n\n\n<p>\u6a21\u5757\u5e38\u901a\u8fc7\u8fd9\u79cd\u5f62\u5f0f\u63d0\u4f9b\u4e00\u4e9b\u65b9\u4fbf\u7684\u7528\u6237\u63a5\u53e3, \u6216\u7528\u4e8e\u6d4b\u8bd5 (\u628a\u6a21\u5757\u5f53\u811a\u672c\u6267\u884c\u4e00\u4e2a\u6d4b\u8bd5\u5957\u4ef6).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.1.2. \u6a21\u5757\u641c\u7d22\u8def\u5f84<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#tut-searchpath\"><\/a><\/h3>\n\n\n\n<p id=\"index-0\">\u5f53\u540d\u4e3a&nbsp;<code>spam<\/code>&nbsp;\u7684\u6a21\u5757\u5bfc\u5165\u65f6, \u89e3\u91ca\u5668\u4f1a\u5148\u4ece\u5185\u5efa\u6a21\u5757\u5c1d\u8bd5\u5339\u914d. \u5982\u679c\u6ca1\u627e\u5230, \u5219\u5c06\u5728&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/sys.html#sys.path\"><code>sys.path<\/code><\/a>&nbsp;\u8bb0\u5f55\u7684\u6240\u6709\u76ee\u5f55\u4e2d\u641c\u7d22&nbsp;<code>spam.py<\/code>&nbsp;\u6587\u4ef6. \u800c&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/sys.html#sys.path\"><code>sys.path<\/code><\/a>&nbsp;\u5219\u7531\u4ee5\u4e0b\u573a\u666f\u58f0\u660e:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5305\u542b\u5bfc\u5165\u811a\u672c\u7684\u76ee\u5f55 (\u5373\u5f53\u524d\u76ee\u5f55)<\/li>\n\n\n\n<li><a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/using\/cmdline.html#envvar-PYTHONPATH\"><code>PYTHONPATH<\/code><\/a>&nbsp;(\u4e00\u4e2a\u76ee\u5f55\u5217\u8868,\u5176\u5f62\u5f0f\u540cshell \u53d8\u91cf&nbsp;<code>PATH<\/code>&nbsp;\u7684\u8bed\u6cd5).<\/li>\n\n\n\n<li>\u5b89\u88dd\u65f6\u5b9a\u4e49\u7684\u9ed8\u8ba4\u76ee\u5f55.<\/li>\n<\/ul>\n\n\n\n<p>Python\u7a0b\u5e8f\u521d\u59cb\u5316\u540e, \u4f9d\u7136\u53ef\u4ee5\u4fee\u6539&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/sys.html#sys.path\"><code>sys.path<\/code><\/a>&nbsp;. \u8be5\u76ee\u5f55\u5305\u542b\u8fd0\u884c\u7684\u811a\u672c\u653e\u7f6e\u5728\u641c\u7d22\u8def\u5f84\u7684\u5f00\u59cb, \u6807\u51c6\u5e93\u7684\u8def\u5f84\u4e4b\u524d. \u8fd9\u610f\u5473\u7740, \u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u7684\u811a\u672c\u5c06\u88ab\u4f18\u5148\u52a0\u8f7d, \u6240\u4ee5\u5982\u679c\u540c\u7cfb\u7edf\u6a21\u5757\u6709\u91cd\u540d\u73b0\u8c61\u65f6, \u8fd9\u901a\u5e38\u4f1a\u629b\u51fa\u4e00\u4e2a\u9519\u8bef.<\/p>\n\n\n\n<p>\u53c2\u770b&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#tut-standardmodules\">\u6807\u51c6\u6a21\u5757<\/a>&nbsp;\u5c0f\u8282\u83b7\u53d6\u66f4\u591a\u4fe1\u606f.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.1.3. \u201c\u5df2\u7f16\u8bd1\u201d \u7684 Python \u6587\u4ef6<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#id12\"><\/a><\/h3>\n\n\n\n<p>\u4e3a\u4e86\u51cf\u5c11\u4f7f\u7528\u4e86\u5927\u91cf\u6807\u51c6\u6a21\u5757\u7684\u5c0f\u7a0b\u5e8f\u7684\u542f\u52a8\u65f6\u95f4, \u5982\u679c&nbsp;<code>spam.py<\/code>&nbsp;\u6240\u5728\u76ee\u5f55\u4e0b\u4e2d\u6709\u540d\u4e3a&nbsp;<code>spam.pyc<\/code>&nbsp;\u7684\u6587\u4ef6, \u89e3\u91ca\u5668\u5c31\u4f1a\u4f18\u5148\u5bfc\u5165&nbsp;<code>spam<\/code>&nbsp;\u6a21\u5757\u7684\u8fd9\u4e00 \u201c\u5df2\u7f16\u8bd1\u5b57\u8282\u201d \u7248\u672c\u6587\u4ef6. \u7528\u6765\u521b\u5efa&nbsp;<code>spam.pyc<\/code>&nbsp;\u7684&nbsp;<code>spam.py<\/code>&nbsp;\u7684\u7248\u672c\u4fee\u6539\u65f6\u95f4\u88ab\u8bb0\u5f55\u5728&nbsp;<code>spam.pyc<\/code>&nbsp;\u4e2d, \u5982\u679c\u4e0d\u5339\u914d\u7684\u8bdd,&nbsp;<code>.pyc<\/code>&nbsp;\u6587\u4ef6\u5c31\u4f1a\u88ab\u5ffd\u7565.<\/p>\n\n\n\n<p>\u4e00\u822c, \u4f60\u65e0\u9700\u7279\u610f\u505a\u4ec0\u4e48\u6765\u521b\u5efa&nbsp;<code>spam.pyc<\/code>&nbsp;\u6587\u4ef6. \u6bcf\u6b21&nbsp;<code>spam.py<\/code>&nbsp;\u88ab\u6210\u529f\u7f16\u8bd1\u540e, \u90fd\u4f1a\u5c1d\u8bd5\u628a\u7ed3\u679c\u5199\u5165\u5230&nbsp;<code>spam.pyc<\/code>. \u8fd9\u65f6\u6709\u4efb\u4f55\u95ee\u9898,\u5e76\u4e0d\u4f1a\u629b\u51fa\u9519\u8bef; \u5982\u679c\u56e0\u67d0\u4e9b\u539f\u56e0\u5bfc\u81f4\u8fd9\u6587\u4ef6\u6ca1\u6709\u88ab\u5b8c\u5168\u7684\u88ab\u5199\u5165, \u90a3\u4e48\u4ea7\u751f\u7684&nbsp;<code>spam.pyc<\/code>&nbsp;\u6587\u4ef6\u4f1a\u88ab\u8fa8\u522b\u51fa\u662f\u65e0\u6548\u7684, \u4ece\u800c\u5728\u5bfc\u5165\u65f6\u88ab\u5ffd\u7565.&nbsp;<code>spam.pyc<\/code>&nbsp;\u6587\u4ef6\u7684\u5185\u5bb9\u662f\u5e73\u53f0\u65e0\u5173\u7684, \u56e0\u6b64, \u4e00\u4e2a Python \u6a21\u5757\u76ee\u5f55\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u4f53\u7cfb\u67b6\u6784\u4e2d\u5171\u4eab.<\/p>\n\n\n\n<p>\u7ed9\u4e13\u5bb6\u7684\u5c0f\u6280\u5de7:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53\u4f7f\u7528&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/using\/cmdline.html#cmdoption-o\"><code>-O<\/code><\/a>&nbsp;\u53c2\u6570\u6765\u8c03\u7528Python \u89e3\u91ca\u5668\u65f6, python\u4f1a\u5bf9\u4ee3\u7801\u8fdb\u884c\u4f18\u5316,\u5e76\u5b58\u5165\u5728&nbsp;<code>.pyo<\/code>&nbsp;\u6587\u4ef6\u91cc. \u5f53\u524d\u4f18\u5316\u5668\u4ec5\u4ec5\u53ea\u662f\u79fb\u9664\u4e86&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#assert\"><code>assert<\/code><\/a>&nbsp;\u8bed\u53e5. \u5f53\u4f7f\u7528&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/using\/cmdline.html#cmdoption-o\"><code>-O<\/code><\/a>&nbsp;\u65f6,&nbsp;<em>\u6240\u6709<\/em>&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/glossary.html#term-bytecode\">bytecode<\/a>&nbsp;\u90fd\u88ab\u4f18\u5316\u4e86; \u6240\u6709&nbsp;.pyc&nbsp;\u6587\u4ef6\u88ab\u5ffd\u7565, \u800c&nbsp;<code>.py<\/code>&nbsp;\u6587\u4ef6\u88ab\u7f16\u8bd1\u4e3a\u4f18\u5316\u7684\u5b57\u8282\u7801.<\/li>\n\n\n\n<li>\u4f20\u9012\u4e24\u4e2a&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/using\/cmdline.html#cmdoption-o\"><code>-O<\/code><\/a>&nbsp;\u53c2\u6570\u5230 Python \u89e3\u91ca\u5668 (<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/using\/cmdline.html#cmdoption-oo\"><code>-OO<\/code><\/a>) \u4f1a\u4f7f\u7f16\u8bd1\u5668\u5bf9\u5b57\u8282\u7801\u8fdb\u4e00\u6b65\u4f18\u5316, \u800c\u8be5\u6b65\u9aa4\u5728\u6781\u5c11\u7684\u60c5\u51b5\u4e0b\u4f1a\u4ea7\u751f\u53d1\u751f\u6545\u969c\u7684\u7a0b\u5e8f. \u4e00\u822c\u5730, \u53ea\u662f\u5c06&nbsp;<code>__doc__<\/code>&nbsp;\u5b57\u7b26\u4e32\u88ab\u4ece\u5b57\u8282\u7801\u4e2d\u79fb\u9664, \u4ee5\u4ea7\u751f\u66f4\u4e3a\u7d27\u51d1\u7684&nbsp;<code>.pyo<\/code>&nbsp;\u6587\u4ef6. \u56e0\u4e3a\u6709\u4e9b\u7a0b\u5e8f\u53ef\u80fd\u4f9d\u8d56\u4e8e\u8fd9\u4e9b, \u56e0\u6b64, \u5efa\u8bae\u53ea\u6709\u5f53\u4f60\u771f\u6b63\u660e\u786e\u8fd9\u610f\u5473\u7740\u4ec0\u4e48\u65f6,\u624d\u4f7f\u7528\u8fd9\u4e2a\u9009\u9879.<\/li>\n\n\n\n<li>\u7a0b\u5e8f\u4ece&nbsp;<code>.pyc<\/code>&nbsp;\u6216&nbsp;<code>.pyo<\/code>&nbsp;\u6587\u4ef6\u91cc\u8bfb\u53d6\u65f6, \u5e76\u4e0d\u4f1a\u6bd4\u5b83\u4ece&nbsp;<code>.py<\/code>&nbsp;\u6587\u4ef6\u4e2d\u8bfb\u53d6\u4f1a\u6709\u66f4\u5feb\u7684\u6267\u884c\u901f\u5ea6; \u552f\u4e00\u63d0\u9ad8\u7684\u662f\u8f7d\u5165\u901f\u5ea6.<\/li>\n\n\n\n<li>\u5728\u5728\u547d\u4ee4\u884c\u4e2d\u76f4\u63a5\u8c03\u7528\u811a\u672c\u8fd0\u884c\u65f6, \u7f16\u8bd1\u540e\u7684\u5b57\u8282\u7801\u4e0d\u4f1a\u88ab\u5199\u5165&nbsp;<code>.pyc<\/code>&nbsp;\u6216&nbsp;<code>.pyo<\/code>&nbsp;\u6587\u4ef6. \u56e0\u6b64, \u901a\u8fc7\u79fb\u52a8\u8be5\u811a\u672c\u7684\u5927\u91cf\u4ee3\u7801\u5230\u4e00\u4e2a\u6a21\u5757, \u5e76\u7531\u4e00\u4e2a\u5c0f\u7684\u5f15\u5bfc\u811a\u672c\u6765\u5bfc\u5165\u8fd9\u4e2a\u6a21\u5757, \u53ef\u80fd\u51cf\u5c11\u8fd9\u4e2a\u811a\u672c\u7684\u542f\u52a8\u65f6\u95f4. \u4e5f\u53ef\u4ee5\u76f4\u63a5\u5728\u547d\u4ee4\u884c\u91cc\u76f4\u63a5\u547d\u540d\u4e00\u4e2a&nbsp;<code>.pyc<\/code>&nbsp;\u6216&nbsp;<code>.pyo<\/code>&nbsp;\u6587\u4ef6.<\/li>\n\n\n\n<li>\u5bf9\u4e8e\u540c\u4e00\u4e2a\u6a21\u5757, \u53ef\u4ee5\u53ea\u5305\u542b&nbsp;<code>spam.pyc<\/code>&nbsp;(\u6216\u8005&nbsp;<code>spam.pyo<\/code>&nbsp;\u5f53\u4f7f\u7528&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/using\/cmdline.html#cmdoption-o\"><code>-O<\/code><\/a>&nbsp;\u65f6) \u6587\u4ef6\u800c\u65e0\u9700&nbsp;<code>spam.py<\/code>&nbsp;\u6587\u4ef6. \u4f7f\u7528\u8fd9\u79cd\u5f62\u5f0f\u53ef\u7528\u4ee5\u53d1\u5e03 Python\u4ee3\u7801\u5e93, \u5e76\u4f7f\u5f97\u53cd\u7f16\u8bd1\u5de5\u7a0b\u6709\u4e00\u5b9a\u7684\u96be\u5ea6.<\/li>\n\n\n\n<li>\u6a21\u5757&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/compileall.html#module-compileall\"><code>compileall<\/code><\/a>&nbsp;\u53ef\u4ee5\u4e3a\u4e00\u4e2a\u76ee\u5f55\u4e0b\u7684\u6240\u6709\u6a21\u5757\u521b\u5efa&nbsp;<code>.pyc<\/code>&nbsp;\u6587\u4ef6 (\u6216&nbsp;<code>.pyo<\/code>&nbsp;\u6587\u4ef6, \u5f53\u4f7f\u7528&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/using\/cmdline.html#cmdoption-o\"><code>-O<\/code><\/a>&nbsp;\u65f6).<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">6.2. \u6807\u51c6\u6a21\u5757<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#tut-standardmodules\"><\/a><\/h2>\n\n\n\n<p id=\"index-4\">Python \u672c\u8eab\u5e26\u6709\u4e00\u4e2a\u6807\u51c6\u5e93, \u6709\u4e13\u95e8\u6587\u6863: Python \u5e93\u53c2\u8003 (\u4ee5\u540e\u7b80\u79f0 \u201c\u5e93\u53c2\u8003\u201d)\u8fdb\u884c\u4ecb\u7ecd.<\/p>\n\n\n\n<p>\u6709\u4e9b\u6a21\u5757\u5185\u5efa\u5230\u4e86\u89e3\u91ca\u5668\u4e2d; \u6709\u4e9b\u64cd\u4f5c\u5c3d\u7ba1\u5e76\u4e0d\u662f\u8bed\u8a00\u6838\u5fc3\u7684\u4e00\u90e8\u5206, \u4f46\u662f\u901a\u8fc7\u6a21\u5757\u5185\u5efa\u63d0\u4f9b\u540e,\u6267\u884c\u6548\u7387\u4e0d\u9519, \u5305\u542b\u64cd\u4f5c\u7cfb\u7edf\u7684\u4e00\u4e9b\u57fa\u672c\u8bbf\u95ee, \u4f8b\u5982\u7cfb\u7edf\u8c03\u7528.<\/p>\n\n\n\n<p>\u8fd9\u79cd\u6a21\u5757\u80fd\u6839\u636e\u4e0d\u540c\u7684\u64cd\u4f5c\u7cfb\u7edf\u8fdb\u884c\u4e13\u95e8\u914d\u7f6e, \u4f8b\u5982,\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/winreg.html#module-winreg\"><code>winreg<\/code><\/a>\u00a0\u6a21\u5757\u53ea\u5728 Windows \u7cfb\u7edf\u4e2d\u63d0\u4f9b. \u6709\u4e00\u4e2a\u7279\u522b\u7684\u6a21\u5757\u9700\u8981\u7279\u522b\u6ce8\u610f:\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/sys.html#module-sys\"><code>sys<\/code><\/a>, \u5b83\u5185\u5efa\u4e8e\u6bcf\u4e2a Python \u89e3\u91ca\u5668. \u5176\u4e2d\u53d8\u91cf\u00a0<code>sys.ps1<\/code>\u00a0\u548c\u00a0<code>sys.ps2<\/code>\u00a0\u5b9a\u4e49\u4e86\u7528\u4e8e\u4e3b\u548c\u6b21\u63d0\u793a\u7b26\u7684\u5b57\u7b26\u4e32:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0importsys<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>sys.ps1<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2018>>> \u2018\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>sys.ps2 <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u2018\u2026 \u2018\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>sys.ps1 = \u2018C> \u2018<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> C> print(\u2018Yuck!\u2019) <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">Yuck!<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> C><\/p>\n\n\n\n<p>\u53ea\u6709\u89e3\u91ca\u5668\u5728\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u8fd0\u884c\u65f6,\u8fd9\u4e24\u4e2a\u53d8\u91cf\u624d\u6709\u5b9a\u4e49.<\/p>\n\n\n\n<p>\u53d8\u91cf\u00a0<code>sys.path<\/code>\u00a0\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\u5217\u8868, \u5b83\u4e3a\u89e3\u91ca\u5668\u6307\u5b9a\u4e86\u6a21\u5757\u7684\u641c\u7d22\u8def\u5f84. \u5b83\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u00a0<code>PATHONPATH<\/code>\u00a0\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u9ed8\u8ba4\u8def\u5f84, \u5f53\u6ca1\u6709\u8bbe\u7f6e\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/using\/cmdline.html#envvar-PYTHONPATH\"><code>PYTHONPATH<\/code><\/a>\u00a0\u65f6, \u5c31\u4f7f\u7528\u5185\u5efa\u9ed8\u8ba4\u503c\u6765\u521d\u59cb\u5316. \u4f60\u53ef\u4ee5\u901a\u8fc7\u6807\u51c6\u5217\u8868\u64cd\u4f5c\u6765\u4fee\u8ba2\u4e4b:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0importsys<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>sys.path.append(\u2018\/ufs\/guido\/lib\/python\u2019)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6.3.&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#dir\"><code>dir()<\/code><\/a>&nbsp;\u51fd\u5f0f<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#dir\"><\/a><\/h2>\n\n\n\n<p>\u5185\u5efa\u51fd\u5f0f\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#dir\"><code>dir()<\/code><\/a>\u00a0\u7528\u4e8e\u627e\u51fa\u4e00\u4e2a\u6a21\u5757\u91cc\u5b9a\u4e49\u4e86\u90a3\u4e9b\u540d\u5b57. \u5b83\u8fd4\u56de\u4e00\u4e2a\u6709\u5e8f\u5b57\u4e32\u5217\u8868:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0importfibo<\/strong>,\u00a0<strong>sys<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>dir(fibo)<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> [\u2018__name__\u2019, \u2018fib\u2019, \u2018fib2\u2019]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>dir(sys)<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> [\u2018__displayhook__\u2019, \u2018__doc__\u2019, \u2018__excepthook__\u2019, \u2018__name__\u2019, \u2018__stderr__\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2018__stdin__\u2019, \u2018__stdout__\u2019, \u2018_getframe\u2019, \u2018api_version\u2019, \u2018argv\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u2018builtin_module_names\u2019, \u2018byteorder\u2019, \u2018callstats\u2019, \u2018copyright\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2018displayhook\u2019, \u2018exc_info\u2019, \u2018excepthook\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2018exec_prefix\u2019, \u2018executable\u2019, \u2018exit\u2019, \u2018getdefaultencoding\u2019, \u2018getdlopenflags\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u2018getrecursionlimit\u2019, \u2018getrefcount\u2019, \u2018hexversion\u2019, \u2018maxint\u2019, \u2018maxunicode\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2018meta_path\u2019, \u2018modules\u2019, \u2018path\u2019, \u2018path_hooks\u2019, \u2018path_importer_cache\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u2018platform\u2019, \u2018prefix\u2019, \u2018ps1\u2019, \u2018ps2\u2019, \u2018setcheckinterval\u2019, \u2018setdlopenflags\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2018setprofile\u2019, \u2018setrecursionlimit\u2019, \u2018settrace\u2019, \u2018stderr\u2019, \u2018stdin\u2019, \u2018stdout\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2018version\u2019, \u2018version_info\u2019, \u2018warnoptions\u2019]<\/p>\n\n\n\n<p>\u4e0d\u7ed9\u53c2\u6570\u65f6,\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#dir\"><code>dir()<\/code><\/a>\u00a0\u5c31\u7f57\u5217\u51fa\u5f53\u524d\u5df2\u5b9a\u4e49\u7684\u6240\u6709\u540d\u5b57.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>a = [1, 2, 3, 4, 5]\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0importfibo<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>>>>\u00a0<\/strong>fib = fibo.fib<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>>>>\u00a0<\/strong>dir()<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> [\u2018__builtins__\u2019, \u2018__doc__\u2019, \u2018__file__\u2019, \u2018__name__\u2019, \u2018a\u2019, \u2018fib\u2019, \u2018fibo\u2019, \u2018sys\u2019]<\/p>\n\n\n\n<p>\u6ce8\u610f, \u5b83\u5217\u4e3e\u51fa\u4e86\u6240\u6709\u7c7b\u578b\u7684\u540d\u5b57: \u53d8\u91cf, \u6a21\u5757, \u51fd\u5f0f, \u7b49\u7b49.<\/p>\n\n\n\n<p id=\"index-7\"><a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/functions.html#dir\"><code>dir()<\/code><\/a>\u00a0\u5e76\u4e0d\u5217\u51fa\u5185\u5efa\u51fd\u5f0f\u548c\u53d8\u91cf\u7684\u540d\u5b57. \u5982\u679c\u4f60\u771f\u5fc3\u60f3\u770b\u4e00\u4e0b, \u53ef\u4ee5\u76f4\u63a5\u67e5\u8be2\u6807\u51c6\u6a21\u5757\u00a0<code>buildin<\/code><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"><strong>>>>\u00a0importbuiltins<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"><strong>>>>\u00a0<\/strong>dir(builtins)<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"> [\u2018ArithmeticError\u2019, \u2018AssertionError\u2019, \u2018AttributeError\u2019, \u2018BaseException\u2019, \u2018Buffer <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">Error\u2019, \u2018BytesWarning\u2019, \u2018DeprecationWarning\u2019, \u2018EOFError\u2019, \u2018Ellipsis\u2019, \u2018Environme<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"> ntError\u2019, \u2018Exception\u2019, \u2018False\u2019, \u2018FloatingPointError\u2019, \u2018FutureWarning\u2019, \u2018Generato <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">rExit\u2019, \u2018IOError\u2019, \u2018ImportError\u2019, \u2018ImportWarning\u2019, \u2018IndentationError\u2019, \u2018IndexErr <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">or\u2019, \u2018KeyError\u2019, \u2018KeyboardInterrupt\u2019, \u2018LookupError\u2019, \u2018MemoryError\u2019, \u2018NameError\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018None\u2019, \u2018NotImplemented\u2019, \u2018NotImplementedError\u2019, \u2018OSError\u2019, \u2018OverflowError\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"> \u2018P endingDeprecationWarning\u2019, \u2018ReferenceError\u2019, \u2018RuntimeError\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018RuntimeWarning\u2019, \u2018 StopIteration\u2019, \u2018SyntaxError\u2019, \u2018SyntaxWarning\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018SystemError\u2019, \u2018SystemExit\u2019, \u2018Ta bError\u2019, \u2018True\u2019, \u2018TypeError\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018UnboundLocalError\u2019, \u2018UnicodeDecodeError\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018Unicod eEncodeError\u2019, \u2018UnicodeError\u2019, \u2018UnicodeTranslateError\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"> \u2018UnicodeWarning\u2019, \u2018UserW arning\u2019, \u2018ValueError\u2019, \u2018Warning\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018ZeroDivisionError\u2019, \u2018__build_class__\u2019, \u2018__deb ug__\u2019, \u2018__doc__\u2019, \u2018__import__\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"> \u2018__name__\u2019, \u2018__package__\u2019, \u2018abs\u2019, \u2018all\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018any\u2019, \u2018ascii\u2019, \u2018bin\u2019, \u2018bool\u2019, \u2018bytearray\u2019, \u2018bytes\u2019, \u2018chr\u2019, \u2018classmethod\u2019, \u2018compile\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018 complex\u2019, \u2018copyright\u2019, \u2018credits\u2019, \u2018delattr\u2019, \u2018dict\u2019, \u2018dir\u2019, \u2018divmod\u2019, \u2018enumerate \u2018,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"> \u2018eval\u2019, \u2018exec\u2019, \u2018exit\u2019, \u2018filter\u2019, \u2018float\u2019, \u2018format\u2019, \u2018frozenset\u2019, \u2018getattr\u2019, \u2018globals\u2019, \u2018hasattr\u2019, <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018hash\u2019, \u2018help\u2019, \u2018hex\u2019, \u2018id\u2019, \u2018input\u2019, \u2018int\u2019, \u2018isinstance\u2019,<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"> \u2018issubclass\u2019, \u2018iter\u2019, \u2018len\u2019, \u2018license\u2019, \u2018list\u2019, \u2018locals\u2019, \u2018map\u2019, \u2018max\u2019, \u2018memory<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\"> view\u2019, \u2018min\u2019, \u2018next\u2019, \u2018object\u2019, \u2018oct\u2019, \u2018open\u2019, \u2018ord\u2019, \u2018pow\u2019, \u2018print\u2019, \u2018property\u2019 , <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">\u2018quit\u2019, \u2018range\u2019, \u2018repr\u2019, \u2018reversed\u2019, \u2019round\u2019, \u2018set\u2019, \u2018setattr\u2019, \u2018slice\u2019, \u2018sort <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\" id=\"index-7\">ed\u2019, \u2018staticmethod\u2019, \u2018str\u2019, \u2018sum\u2019, \u2018super\u2019, \u2018tuple\u2019, \u2018type\u2019, \u2018vars\u2019, \u2018zip\u2019]<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">6.4. \u5305<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#tut-packages\"><\/a><\/h2>\n\n\n\n<p>\u5305\u662f\u4e00\u79cd Python \u6a21\u5757\u547d\u540d\u7a7a\u95f4\u7684\u7ec4\u7ec7\u65b9\u6cd5, \u901a\u8fc7\u4f7f\u7528 \u201c\u5e26\u70b9\u53f7\u7684\u6a21\u5757\u540d\u201d. \u4f8b\u5982, \u6a21\u5757\u540d&nbsp;<code>A.B<\/code>&nbsp;\u6307\u5b9a\u4e86\u4e00\u4e2a\u540d\u4e3a&nbsp;<code>A<\/code>&nbsp;\u7684\u5305\u91cc\u7684\u4e00\u4e2a\u540d\u4e3a&nbsp;<code>B<\/code>&nbsp;\u7684\u5b50\u6a21\u5757. \u5c31\u50cf\u6a21\u5757\u7684\u4f7f\u7528\u4f7f\u4e0d\u540c\u6a21\u5757\u7684\u4f5c\u8005\u907f\u514d\u62c5\u5fc3\u5176\u5b83\u5168\u5c40\u53d8\u91cf\u7684\u540d\u5b57, \u800c\u5e26\u70b9\u53f7\u7684\u6a21\u5757\u4f7f\u5f97\u591a\u6a21\u5757\u5305, \u4f8b\u5982 NumPy \u6216 Python \u56fe\u50cf\u5e93, \u7684\u4f5c\u8005\u907f\u514d\u62c5\u5fc3\u5176\u5b83\u6a21\u5757\u540d.<\/p>\n\n\n\n<p>\u5047\u8bbe\u4f60\u60f3\u8bbe\u8ba1\u4e00\u4e2a\u6a21\u5757\u96c6 (\u4e00\u4e2a \u201c\u5305\u201d), \u7528\u4e8e\u7edf\u4e00\u58f0\u97f3\u6587\u4ef6\u548c\u58f0\u97f3\u6570\u636e\u7684\u5904\u7406. \u6709\u8bb8\u591a\u4e0d\u540c\u7684\u58f0\u97f3\u683c\u5f0f (\u901a\u5e38\u901a\u8fc7\u5b83\u4eec\u7684\u540e\u7f00\u6765\u8fa8\u8ba4, \u4f8b\u5982:\u00a0<code>.wave<\/code>,\u00a0<code>.aiff<\/code>,\u00a0<code>.au<\/code>), \u56e0\u6b64\u4f60\u53ef\u80fd\u9700\u8981\u521b\u5efa\u548c\u7ef4\u62a4\u4e00\u4e2a\u4e0d\u65ad\u589e\u957f\u7684\u6a21\u5757\u96c6, \u7528\u4ee5\u5404\u79cd\u5404\u6837\u7684\u6587\u4ef6\u683c\u5f0f\u95f4\u7684\u8f6c\u6362. \u8fd8\u6709\u8bb8\u591a\u4f60\u60f3\u5bf9\u58f0\u97f3\u6570\u636e\u6267\u884c\u7684\u4e0d\u540c\u64cd\u4f5c (\u4f8b\u5982\u6df7\u9891, \u589e\u52a0\u56de\u97f3, \u5e94\u7528\u4e00\u4e2a\u5747\u8861\u5668\u529f\u80fd, \u521b\u5efa\u4eba\u9020\u7684\u7acb\u4f53\u58f0\u6548\u679c), \u56e0\u6b64, \u4f60\u5c06\u989d\u5916\u7684\u5199\u4e00\u4e2a\u6c38\u65e0\u6b62\u5c3d\u7684\u6a21\u5757\u6d41\u6765\u6267\u884c\u8fd9\u4e9b\u64cd\u4f5c. \u8fd9\u662f\u4f60\u7684\u5305\u7684\u4e00\u4e2a\u53ef\u80fd\u7684\u7ed3\u6784:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">sound\/ \u9876\u7ea7\u5305<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> __init__.py                \u521d\u59cb\u5316\u8fd9\u4e2a\u58f0\u97f3\u5305 <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">formats\/                           \u6587\u4ef6\u683c\u5f0f\u8f6c\u6362\u5b50\u5305<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> __init__.py<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> wavread.py<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> wavwrite.py <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">aiffread.py <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">aiffwrite.py<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> auread.py <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">auwrite.py <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u2026 <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">effects\/              \u97f3\u6548\u5b50\u5305<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> __init__.py<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> echo.py<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> surround.py <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">reverse.py <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u2026<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> filters<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\/ \u8fc7\u6ee4\u5668\u5b50\u5305<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> __init__.py <\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">equalizer.py<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> vocoder.py<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> karaoke.py<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"> \u2026<\/p>\n\n\n\n<p>\u5f53\u5bfc\u5165\u8fd9\u4e2a\u5305\u65f6, Python \u641c\u7d22&nbsp;<code>sys.path<\/code>&nbsp;\u4e0a\u7684\u76ee\u5f55\u4ee5\u5bfb\u627e\u8fd9\u4e2a\u5305\u7684\u5b50\u76ee\u5f55.<\/p>\n\n\n\n<p>\u9700\u8981&nbsp;<code>__init__.py<\/code>&nbsp;\u6587\u4ef6\u6765\u4f7f\u5f97 Python \u77e5\u9053\u8fd9\u4e2a\u76ee\u5f55\u5305\u542b\u4e86\u5305; \u8fd9\u7528\u6765\u9884\u9632\u540d\u5b57\u4e3a\u4e00\u4e2a\u901a\u7528\u540d\u5b57, \u5982&nbsp;<code>string<\/code>, \u7684\u76ee\u5f55\u4ee5\u5916\u5730\u9690\u85cf\u4e86\u5728\u6a21\u5757\u641c\u7d22\u8def\u5f84\u9760\u540e\u7684\u6b63\u5f53\u7684\u6a21\u5757. \u5728\u6700\u7b80\u5355\u7684\u4f8b\u5b50\u91cc,&nbsp;<code>__init__.py<\/code>&nbsp;\u53ef\u4ee5\u5c31\u662f\u4e2a\u7a7a\u6587\u4ef6, \u4f46\u5b83\u4e5f\u53ef\u4ee5\u4e3a\u8fd9\u4e2a\u5305\u6267\u884c\u521d\u59cb\u5316\u4ee3\u7801, \u6216\u8005\u8bbe\u7f6e&nbsp;<code>__all__<\/code>&nbsp;\u53d8\u91cf, \u5728\u540e\u9762\u63cf\u8ff0.<\/p>\n\n\n\n<p>\u5305\u7684\u7528\u6237\u53ef\u4ee5\u5305\u91cc\u7684\u5355\u72ec\u7684\u6a21\u5757, \u4f8b\u5982:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>importsound.effects.echo<\/strong><\/p>\n\n\n\n<p>\u8fd9\u8f7d\u5165\u91cc\u00a0<code>sound.effects.echo<\/code>\u00a0\u5b50\u6a21\u5757. \u4e00\u5b9a\u8981\u4f7f\u7528\u5168\u540d\u6765\u5f15\u7528\u5b83.<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">sound.effects.echo.echofilter(input, output, delay=0.7, atten=4)<\/p>\n\n\n\n<p>\u5bfc\u5165\u5b50\u6a21\u5757\u7684\u4e00\u4e2a\u66ff\u4ee3\u65b9\u6cd5\u662f:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>fromsound.effectsimport<\/strong>\u00a0echo<\/p>\n\n\n\n<p>\u8fd9\u6837\u4e5f\u8f7d\u5165\u00a0<code>echo<\/code>\u00a0\u5b50\u6a21\u5757, \u5e76\u4e14\u53ef\u4ee5\u4e0d\u52a0\u5305\u524d\u7f00\u5730\u4f7f\u7528, \u56e0\u6b64\u53ef\u4ee5\u5982\u4e0b\u5730\u4f7f\u7528:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">echo.echofilter(input, output, delay=0.7, atten=4)<\/p>\n\n\n\n<p>\u53e6\u4e00\u4e2a\u53d8\u79cd\u662f\u76f4\u63a5\u5bfc\u5165\u60f3\u8981\u7684\u51fd\u5f0f\u6216\u53d8\u91cf:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>fromsound.effects.echoimport<\/strong>\u00a0echofilter<\/p>\n\n\n\n<p>\u518d\u4e00\u6b21, \u8f7d\u5165\u4e86&nbsp;<code>echo<\/code>&nbsp;\u5b50\u6a21\u5757, \u4f46\u662f\u4f7f\u5b83\u7684\u51fd\u5f0f&nbsp;<code>echofilter()<\/code>&nbsp;\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528.<\/p>\n\n\n\n<p>\u6ce8\u610f, \u5f53\u4f7f\u7528&nbsp;<code>from&nbsp;package&nbsp;import&nbsp;item<\/code>&nbsp;\u65f6, \u8fd9\u4e2a\u9879\u5373\u53ef\u4ee5\u662f\u8fd9\u4e2a\u5305\u7684\u4e00\u4e2a\u5b50\u6a21\u5757 (\u6216\u5b50\u5305), \u4e5f\u53ef\u4ee5\u662f\u5176\u5b83\u7684\u5b9a\u4e49\u5728\u8fd9\u4e2a\u5305\u91cc\u7684\u540d\u5b57, \u5982\u51fd\u5f0f, \u7c7b\u6216\u53d8\u91cf.&nbsp;<code>import<\/code>&nbsp;\u8bed\u53e5\u9996\u5148\u6d4b\u8bd5\u8fd9\u4e2a\u9879\u662f\u5426\u5728\u5305\u91cc\u5b9a\u4e49; \u5982\u679c\u6ca1\u6709, \u5c31\u5047\u8bbe\u5b83\u662f\u4e00\u4e2a\u6a21\u5757\u5e76\u8bd5\u56fe\u8f7d\u5165\u5b83. \u5982\u679c\u5bfb\u627e\u5b83\u5931\u8d25, \u5c31\u4f1a\u629b\u51fa\u4e00\u4e2a&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/library\/exceptions.html#ImportError\"><code>ImportError<\/code><\/a>.<\/p>\n\n\n\n<p>\u76f8\u53cd\u5730, \u5f53\u4f7f\u7528&nbsp;<code>import&nbsp;item.subitem.subsubitem<\/code>&nbsp;\u65f6, \u9664\u6700\u540e\u7684\u6bcf\u4e00\u9879\u90fd\u5fc5\u987b\u662f\u5305; \u6700\u540e\u4e00\u9879\u53ef\u4ee5\u662f\u6a21\u5757\u6216\u5305, \u4f46\u4e0d\u80fd\u662f\u5728\u4e4b\u524d\u9879\u4e2d\u5b9a\u4e49\u7684\u7c7b, \u51fd\u5f0f\u6216\u53d8\u91cf.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.4.1. \u4ece\u5305\u4e2d\u5bfc\u5165 *<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#tut-pkg-import-star\"><\/a><\/h3>\n\n\n\n<p id=\"index-8\">\u5f53\u5f00\u53d1\u8005\u5199\u4e0b&nbsp;<code>from&nbsp;sound.effects&nbsp;import&nbsp;*<\/code>&nbsp;\u4f1a\u53d1\u751f\u4ec0\u4e48?<\/p>\n\n\n\n<p>\u7406\u60f3\u5730, \u6211\u4eec\u671f\u671b\u7a0b\u5e8f\u4f1a\u4ee5\u4ee5\u67d0\u79cd\u65b9\u6cd5\u8fdb\u5165\u6587\u4ef6\u7cfb\u7edf, \u5bfb\u627e\u5728\u6307\u5b9a\u7684\u5305\u6587\u4ef6\u4e2d,\u627e\u5230\u6240\u6709\u5b50\u6a21\u5757, \u5e76\u628a\u5b83\u4eec\u5168\u90e8\u5bfc\u5165. \u8fd9\u53ef\u80fd\u82b1\u8d39\u5f88\u957f\u7684\u65f6\u95f4, \u800c\u4e14\u5bf9\u5b50\u6a21\u5757\u8fdb\u884c\u663e\u5f0f\u5bfc\u5165\u65f6,\u8fd8\u53ef\u80fd\u5f15\u53d1\u975e\u671f\u5f85\u7684 \u526f\u4f5c\u7528!<\/p>\n\n\n\n<p>~ \u8fd9\u4e9b\u526f\u4f5c\u7528\u53ef\u80fd\u662f\u4ec5\u4ec5\u53d1\u751f\u5728\u663e\u5f0f\u5bfc\u5165\u5b50\u6a21\u5757\u7684\u65f6\u5019\u624d\u4f1a\u53d1\u751f\u7684\u90a3\u4e9b<\/p>\n\n\n\n<p>\u8bd1\u6ce8<\/p>\n\n\n\n<p>@Liam Huang<\/p>\n\n\n\n<p>\u5c3d\u7ba1\u6b64\u5904\u5e76\u6ca1\u6709\u663e\u5f0f\u5bfc\u5165\u5b50\u6a21\u5757 \u4f46\u662f\u5374\u4f1a\u53d1\u751f\u8fd9\u7c7b\u9519\u8bef<\/p>\n\n\n\n<p>\u5bf9\u4e8e\u5305\u4f5c\u8005, \u552f\u4e00\u89e3\u51b3\u65b9\u6848\u662f\u63d0\u4f9b\u5305\u7684\u663e\u5f0f\u7d22\u5f15.&nbsp;<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#import\"><code>import<\/code><\/a>&nbsp;\u8bed\u53e5\u6709\u4ee5\u4e0b\u7ea6\u5b9a:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u4e00\u4e2a\u5305\u7684&nbsp;<code>__init__.py<\/code>&nbsp;\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u540d\u4e3a&nbsp;<code>__all__<\/code>&nbsp;\u7684\u5217\u8868,<\/li>\n\n\n\n<li>\u5f53\u9047\u5230&nbsp;<code>from&nbsp;package&nbsp;import&nbsp;*<\/code>&nbsp;\u65f6, \u5b83\u88ab\u7528\u6765\u4f5c\u4e3a\u5bfc\u5165\u7684\u6a21\u5757\u540d\u5b57\u7684\u5217\u8868.<\/li>\n<\/ul>\n\n\n\n<p>\u662f\u5426\u5728\u53d1\u5e03\u5305\u7684\u65b0\u7248\u672c\u65f6\u4fdd\u6301\u8fd9\u4e2a\u5217\u8868\u7684\u66f4\u65b0\u53d6\u51b3\u4e8e\u5305\u7684\u4f5c\u8005. \u5305\u4f5c\u8005\u4e5f\u53ef\u80fd\u51b3\u5b9a\u4e0d\u652f\u6301\u5b83, \u5982\u679c\u4ed6\u4eec\u6ca1\u6709\u53d1\u73b0\u4ece\u4ed6\u4eec\u7684\u5305\u91cc\u5bfc\u5165 * \u7684\u7528\u9014. \u4f8b\u5982, \u6587\u4ef6\u00a0<code>sound\/effects\/__init__.py<\/code>\u00a0\u53ef\u80fd\u5305\u542b\u5982\u4e0b\u4ee3\u7801<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">__all__ = [\u201cecho\u201d, \u201csurround\u201d, \u201creverse\u201d]<\/p>\n\n\n\n<p>\u8fd9\u610f\u5473\u8fd9&nbsp;<code>from&nbsp;sound.effects&nbsp;import&nbsp;*<\/code>&nbsp;\u5c06\u5bfc\u5165&nbsp;<code>sound<\/code>&nbsp;\u4e2d\u8fd9\u51e0\u4e2a\u540d\u5b57\u7684\u5b50\u6a21\u5757.<\/p>\n\n\n\n<p>\u5982\u679c\u00a0<code>__all__<\/code>\u00a0\u6ca1\u6709\u88ab\u5b9a\u4e49,\u00a0<code>from\u00a0sound.effects\u00a0import\u00a0*<\/code>\u00a0\u8bed\u53e5\u00a0<em>\u4e0d<\/em>\u00a0\u628a\u5305\u00a0<code>sound.effects<\/code>\u00a0\u4e2d\u6240\u6709\u7684\u5b50\u6a21\u5757\u90fd\u5bfc\u5165\u5230\u5f53\u524d\u547d\u540d\u7a7a\u95f4\u91cc; \u5b83\u53ea\u80fd\u786e\u4fdd\u5305\u00a0<code>sound.effects<\/code>\u00a0\u88ab\u5bfc\u5165\u4e86 (\u53ef\u80fd\u540c\u65f6\u8fd0\u884c\u5728\u00a0<code>__init__.py`<\/code>\u00a0\u91cc\u7684\u4e00\u4e9b\u521d\u59cb\u5316\u4ee3\u7801), \u5e76\u968f\u540e\u5bfc\u5165\u5305\u4e2d\u5b9a\u4e49\u7684\u4efb\u4f55\u540d\u5b57. \u8fd9\u5305\u542b\u4efb\u4f55\u5728\u00a0<code>__init__.py<\/code>\u00a0\u5b9a\u4e49\u7684 \u4efb\u4f55\u540d\u5b57 (\u548c\u663e\u5f0f\u8f7d\u5165\u7684\u5b50\u6a21\u5757). \u5b83\u8fd8\u5305\u542b\u901a\u8fc7\u524d\u9762\u7684\u00a0<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/reference\/simple_stmts.html#import\"><code>import<\/code><\/a>\u00a0\u8bed\u53e5\u663e\u5f0f\u8f7d\u5165\u7684\u5305\u7684\u5b50\u6a21\u5757. \u8003\u8651\u8fd9\u6bb5\u4ee3\u7801:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>importsound.effects.echo<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>importsound.effects.surround<\/strong><\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>fromsound.effectsimport<\/strong>\u00a0*<\/p>\n\n\n\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d, \u6a21\u5757&nbsp;<code>echo<\/code>&nbsp;\u548c&nbsp;<code>surround<\/code>&nbsp;\u88ab\u5bfc\u5165\u5230\u5f53\u524d\u547d\u540d\u7a7a\u95f4, \u56e0\u4e3a\u5f53 \u6267\u884c&nbsp;<code>from...import<\/code>&nbsp;\u8bed\u53e5\u65f6\u5b83\u4eec\u5c31\u88ab\u5b9a\u4e49\u5728\u5305&nbsp;<code>sound.effects<\/code>&nbsp;\u91cc. (\u5f53\u5b9a\u4e49&nbsp;<code>__all__<\/code>&nbsp;\u5b9a\u4e49\u65f6, \u8fd9\u4e5f\u4f1a\u5de5\u4f5c.)<\/p>\n\n\n\n<p>\u867d\u7136\u6709\u4e9b\u6a21\u5757\u88ab\u8bbe\u8ba1\u6210\u5f53\u4f7f\u7528&nbsp;import *&nbsp;\u65f6\u4ec5\u5bfc\u51fa\u9075\u5faa\u7279\u5b9a\u6a21\u5f0f\u7684\u540d\u79f0, \u4f46\u662f\u5728\u4ea7\u54c1\u4ee3\u7801\u4e2d\u4ecd\u7136\u611f\u89c9\u7b97\u7cdf\u7cd5\u5b9e\u8df5.<\/p>\n\n\n\n<p>\u8bb0\u4f4f, \u4f7f\u7528&nbsp;from Package import specific_submodule&nbsp;\u662f\u6ca1\u6709\u95ee\u9898\u7684! \u4e8b\u5b9e\u4e0a, \u8fd9\u662f\u63a8\u8350\u7684\u7528\u6cd5, \u53ea\u5728\u4ee5\u4e0b\u60c5\u51b5\u4f8b\u5916: \u6b63\u5728\u5bfc\u5165\u7684\u6a21\u5757\u9700\u8981\u4f7f\u7528\u7684\u5b50\u6a21\u5757\u4e0e\u5176\u4ed6\u5305\u4e2d\u7684\u5b50\u6a21\u5757\u5177\u6709\u76f8\u540c\u7684\u540d\u5b57.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.4.2. \u5185\u90e8\u5305\u53c2\u8003<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#id16\"><\/a><\/h3>\n\n\n\n<p>\u5f53\u5305\u88ab\u6784\u9020\u5230\u5b50\u5305\u65f6 (\u5982\u4f8b\u5b50\u4e2d\u7684&nbsp;<code>sound<\/code>&nbsp;\u5305), \u4f60\u53ef\u4ee5\u72ec\u7acb\u5730\u5bfc\u5165\u6765\u83b7\u53d6\u5144\u5f1f\u5305\u7684\u5b50\u6a21\u5757\u7684\u5f15\u7528. \u4f8b\u5982, \u5982\u679c\u6a21\u5757&nbsp;<code>sound.filters.vocoder<\/code>&nbsp;\u9700\u8981\u4f7f\u7528&nbsp;<code>sound.effects<\/code>&nbsp;\u5305\u4e0b\u7684&nbsp;<code>echo<\/code>&nbsp;\u6a21\u5757, \u5c31\u53ef\u4ee5\u4f7f\u7528&nbsp;<code>from&nbsp;sound.effects&nbsp;import&nbsp;echo<\/code>.<\/p>\n\n\n\n<p>\u4f60\u8fd8\u53ef\u4ee5\u4f7f\u7528\u76f8\u5bf9\u5bfc\u5165, \u901a\u8fc7 import \u8bed\u53e5\u7684\u00a0<code>from\u00a0module\u00a0import\u00a0name<\/code>\u00a0\u683c\u5f0f. \u8fd9\u4e9b\u5bfc\u5165\u4f7f\u7528\u53e5\u70b9\u6765\u8868\u660e\u6d89\u53ca\u8fd9\u6b21\u76f8\u5bf9\u5bfc\u5165\u7684\u5f53\u524d\u5305\u548c\u7236\u5305. \u4ece\u4f8b\u5b50\u4e2d\u7684\u00a0<code>surround<\/code>\u00a0, \u60a8\u53ef\u4ee5\u4f7f\u7528:<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>from.import<\/strong>\u00a0echo\u00a0<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\"><strong>from..import<\/strong>\u00a0formats<\/p>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background\">\u00a0<strong>from..filtersimport<\/strong>\u00a0equalizer<\/p>\n\n\n\n<p>\u6ce8\u610f, \u76f8\u5bf9\u5bfc\u5165\u57fa\u4e8e\u5f53\u524d\u6a21\u5757\u7684\u540d\u5b57. \u56e0\u4e3a\u4e3b\u6a21\u5757\u7684\u540d\u5b57\u603b\u662f&nbsp;<code>\"__main__\"<\/code>, \u6709\u610f\u7528\u4f5c\u4e00\u4e2a Python \u7a0b\u5e8f\u7684\u4e3b\u6a21\u5757\u7684\u6a21\u5757\u5fc5\u987b\u603b\u4f7f\u7528&nbsp;<code>\u7edd\u5bf9\u5bfc\u5165<\/code>&nbsp;.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.4.3. \u591a\u76ee\u5f55\u7684\u5305<a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#id17\"><\/a><\/h3>\n\n\n\n<p>\u5305\u652f\u6301\u989d\u5916\u4e00\u4e2a\u7279\u6b8a\u7684\u5c5e\u6027,&nbsp;<code>__path__<\/code>&nbsp;. \u5b83\u5728\u6587\u4ef6\u4e2d\u7684\u4ee3\u7801\u6267\u884c\u4e4b\u524d, \u88ab\u521d\u59cb\u5316\u4e3a\u4e00\u4e2a\u5217\u8868, \u5b83\u5305\u542b\u4fdd\u5b58\u5728\u8fd9\u4e2a\u5305\u7684&nbsp;<code>__init__.py<\/code>&nbsp;\u6587\u4ef6\u4e2d\u76ee\u5f55\u540d. \u8fd9\u4e2a\u53d8\u91cf\u53ef\u4ee5\u88ab\u66f4\u6539; \u8fd9\u6837\u505a\u4f1a\u5f71\u54cd\u4ee5\u540e\u5bf9\u5305\u4e2d\u6a21\u5757\u548c\u5b50\u5305\u7684\u641c\u7d22.<\/p>\n\n\n\n<p>\u867d\u7136\u8fd9\u4e2a\u7279\u6027\u4e0d\u7ecf\u5e38\u9700\u8981, \u4f46\u5b83\u53ef\u4ee5\u7528\u4e8e\u6269\u5c55\u5728\u4e00\u4e2a\u5305\u91cc\u53d1\u73b0\u7684\u6a21\u5757\u7684\u96c6\u5408.<\/p>\n\n\n\n<p>Footnotes<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><tbody><tr><td><a href=\"https:\/\/docspy3zh.readthedocs.io\/en\/latest\/tutorial\/modules.html#id9\">[1]<\/a><\/td><td>\u5b9e\u9645\u4e0a, \u51fd\u5f0f\u5b9a\u4e49\u4e5f\u662f \u2018\u88ab\u6267\u884c\u2019 \u7684 \u2018\u8bed\u53e5\u2019; \u6a21\u5757\u7ea7\u51fd\u5f0f\u7684\u6267\u884c\u8ba9\u51fd\u5f0f\u540d\u8fdb\u5165\u8fd9\u4e2a\u6a21\u5757\u7684\u5168\u5c40\u53d8\u91cf\u8868.<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4f60\u4ece Python \u89e3\u91ca\u5668\u9000\u51fa\u540e\u518d\u91cd\u65b0\u8fdb\u5165, \u90a3\u4e48\u4f60\u4e4b\u524d\u5b9a\u4e49\u7684\u6240\u6709 (\u51fd\u5f0f\u548c\u53d8\u91cf) \u90fd\u5c06\u4e22\u5931. \u56e0\u6b64, \u5982 [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-275","post","type-post","status-publish","format-standard","hentry","category-python"],"blocksy_meta":"","_links":{"self":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/275","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/comments?post=275"}],"version-history":[{"count":10,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions"}],"predecessor-version":[{"id":370,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/posts\/275\/revisions\/370"}],"wp:attachment":[{"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/media?parent=275"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/categories?post=275"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ai.gitpp.com\/index.php\/wp-json\/wp\/v2\/tags?post=275"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}