{"id":1065,"date":"2009-05-31T23:32:32","date_gmt":"2009-05-31T15:32:32","guid":{"rendered":"http:\/\/fanhaijun.com\/?p=1065"},"modified":"2009-05-31T23:32:32","modified_gmt":"2009-05-31T15:32:32","slug":"python-import%e6%9c%ba%e5%88%b6%e5%a4%87%e5%bf%98-%e6%a8%a1%e5%9d%97%e6%90%9c%e7%b4%a2%e8%b7%af%e5%be%84syspath%e3%80%81%e5%b5%8c%e5%a5%97import%e3%80%81package-import","status":"publish","type":"post","link":"https:\/\/fanhaijun.com\/?p=1065","title":{"rendered":"Python Import\u673a\u5236\u5907\u5fd8-\u6a21\u5757\u641c\u7d22\u8def\u5f84(sys.path)\u3001\u5d4c\u5957Import\u3001package Import"},"content":{"rendered":"<p>\u6a21\u5757\u7684\u641c\u7d22\u8def\u5f84<\/p>\n<p>\u6a21\u5757\u7684\u641c\u7d22\u8def\u5f84\u90fd\u653e\u5728\u4e86sys.path\u5217\u8868\u4e2d\uff0c\u5982\u679c\u7f3a\u7701\u7684sys.path\u4e2d\u6ca1\u6709\u542b\u6709\u81ea\u5df1\u7684\u6a21\u5757\u6216\u5305\u7684\u8def\u5f84\uff0c\u53ef\u4ee5\u52a8\u6001\u7684\u52a0\u5165\uff08sys.path.apend\uff09\u5373\u53ef\u3002\u4e0b\u9762\u662fsys.path\u5728Windows\u5e73\u53f0\u4e0b\u7684\u6dfb\u52a0\u89c4\u5219\u3002<\/p>\n<p>1\u3001sys.path\u7b2c\u4e00\u4e2a\u8def\u5f84\u5f80\u5f80\u662f\u4e3b\u6a21\u5757\u6240\u5728\u7684\u76ee\u5f55\u3002\u5728\u4ea4\u4e92\u73af\u5883\u4e0b\u6dfb\u52a0\u4e00\u4e2a\u7a7a\u9879\uff0c\u5b83\u5bf9\u5e94\u5f53\u524d\u76ee\u5f55\u3002 <\/p>\n<p>2\u3001\u5982\u679cPYTHONPATH\u73af\u5883\u53d8\u91cf\u5b58\u5728\uff0csys.path\u4f1a\u52a0\u8f7d\u6b64\u53d8\u91cf\u6307\u5b9a\u7684\u76ee\u5f55\u3002<\/p>\n<p>3\u3001\u6211\u4eec\u5c1d\u8bd5\u627e\u5230Python Home\uff0c\u5982\u679c\u8bbe\u7f6e\u4e86PYTHONHOME\u73af\u5883\u53d8\u91cf\uff0c\u6211\u4eec\u8ba4\u4e3a\u8fd9\u5c31\u662fPython Home\uff0c\u5426\u5219\uff0c\u6211\u4eec\u4f7f\u7528python.exe\u6240\u5728\u76ee\u5f55\u627e\u5230lib\\os.py\u53bb\u63a8\u65adPython Home\u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u786e\u5b9e\u627e\u5230\u4e86Python Home\uff0c\u5219\u76f8\u5173\u7684\u5b50\u76ee\u5f55\uff08Lib\u3001plat-win\u3001lib-tk\u7b49\uff09\u5c06\u4ee5Python Home\u4e3a\u57fa\u7840\u52a0\u5165\u5230sys.path\uff0c\u5e76\u5bfc\u5165\uff08\u6267\u884c\uff09lib\/site.py\uff0c\u5c06site-specific\u76ee\u5f55\u53ca\u5176\u4e0b\u7684\u5305\u52a0\u5165\u3002<\/p>\n<p>\u5982\u679c\u6211\u4eec\u6ca1\u6709\u627e\u5230Python Home\uff0c\u5219\u628a\u6ce8\u518c\u8868Software\\Python\\PythonCore\\2.5\\PythonPath\u7684\u9879\u52a0\u5165sys.path\uff08HKLM\u548c HKCU\u5408\u5e76\u540e\u52a0\u5165\uff09\uff0c\u4f46\u76f8\u5173\u7684\u5b50\u76ee\u5f55\u4e0d\u4f1a\u81ea\u52a8\u6dfb\u52a0\u7684\u3002<\/p>\n<p>4\u3001\u5982\u679c\u6211\u4eec\u6ca1\u6709\u627e\u5230Python Home\uff0c\u5e76\u4e14\u6ca1\u6709PYTHONPATH\u73af\u5883\u53d8\u91cf\uff0c\u5e76\u4e14\u4e0d\u80fd\u5728\u6ce8\u518c\u8868\u4e2d\u627e\u5230PythonPath\uff0c\u90a3\u4e48\u7f3a\u7701\u76f8\u5bf9\u8def\u5f84\u5c06\u52a0\u5165\uff08\u5982\uff1a.\\Lib;.\\plat-win\u7b49\uff09\u3002<\/p>\n<p>\u603b\u7ed3\u5982\u4e0b<\/p>\n<p>\u5f53\u5728\u5b89\u88c5\u597d\u7684\u4e3b\u76ee\u5f55\u4e2d\u8fd0\u884cPython.exe\u65f6\uff0c\u9996\u5148\u63a8\u65adPython Home\uff0c\u5982\u679c\u627e\u5230\u4e86PythonHome\uff0c\u6ce8\u518c\u8868\u4e2d\u7684PythonPath\u5c06\u88ab\u5ffd\u7565\uff1b\u5426\u5219\u5c06\u6ce8\u518c\u8868\u7684PythonPath\u52a0\u5165\u3002<\/p>\n<p>\u5982\u679cPYTHONPATH\u73af\u5883\u53d8\u91cf\u5b58\u5728\uff0csys.path\u80af\u5b9a\u4f1a\u52a0\u8f7d\u6b64\u53d8\u91cf\u6307\u5b9a\u7684\u76ee\u5f55\u3002<\/p>\n<p>\u5982\u679cPython.exe\u5728\u53e6\u5916\u7684\u4e00\u4e2a\u76ee\u5f55\u4e0b\uff08\u4e0d\u540c\u7684\u76ee\u5f55\uff0c\u6bd4\u5982\u901a\u8fc7COM\u5d4c\u5165\u5230\u5176\u4ed6\u7a0b\u5e8f\uff09\uff0cPython Home\u5c06\u4e0d\u63a8\u65ad\uff0c\u6b64\u65f6\u6ce8\u518c\u8868\u7684PythonPath\u5c06\u88ab\u4f7f\u7528\u3002<\/p>\n<p>\u5982\u679cPython.exe\u4e0d\u80fd\u53d1\u73b0\u4ed6\u7684\u4e3b\u76ee\u5f55\uff08PythonHome\uff09\uff0c\u5e76\u4e14\u6ce8\u518c\u8868\u4e5f\u6ca1\u6709PythonPath\uff0c\u5219\u5c06\u52a0\u5165\u7f3a\u7701\u7684\u76f8\u5bf9\u76ee\u5f55\u3002<\/p>\n<p>\u6807\u51c6Import<\/p>\n<p>Python\u4e2d\u6240\u6709\u52a0\u8f7d\u5230\u5185\u5b58\u7684\u6a21\u5757\u90fd\u653e\u5728sys.modules\u3002\u5f53import\u4e00\u4e2a\u6a21\u5757\u65f6\u9996\u5148\u4f1a\u5728\u8fd9\u4e2a\u5217\u8868\u4e2d\u67e5\u627e\u662f\u5426\u5df2\u7ecf\u52a0\u8f7d\u4e86\u6b64\u6a21\u5757\uff0c\u5982\u679c\u52a0\u8f7d\u4e86\u5219\u53ea\u662f\u5c06\u6a21\u5757\u7684\u540d\u5b57\u52a0\u5165\u5230\u6b63\u5728\u8c03\u7528import\u7684\u6a21\u5757\u7684Local\u540d\u5b57\u7a7a\u95f4\u4e2d\u3002\u5982\u679c\u6ca1\u6709\u52a0\u8f7d\u5219\u4ecesys.path\u76ee\u5f55\u4e2d\u6309\u7167\u6a21\u5757\u540d\u79f0\u67e5\u627e\u6a21\u5757\u6587\u4ef6\uff0c\u6a21\u5757\u6587\u4ef6\u53ef\u4ee5\u662fpy\u3001pyc\u3001pyd\uff0c\u627e\u5230\u540e\u5c06\u6a21\u5757\u8f7d\u5165\u5185\u5b58\uff0c\u5e76\u52a0\u5165\u5230sys.modules\u4e2d\uff0c\u5e76\u5c06\u540d\u79f0\u5bfc\u5165\u5230\u5f53\u524d\u7684Local\u540d\u5b57\u7a7a\u95f4\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u51fa\u4e86\uff0c\u4e00\u4e2a\u6a21\u5757\u4e0d\u4f1a\u91cd\u590d\u8f7d\u5165\u3002\u591a\u4e2a\u4e0d\u540c\u7684\u6a21\u5757\u90fd\u53ef\u4ee5\u7528import\u5f15\u5165\u540c\u4e00\u4e2a\u6a21\u5757\u5230\u81ea\u5df1\u7684Local\u540d\u5b57\u7a7a\u95f4\uff0c\u5176\u5b9e\u80cc\u540e\u7684PyModuleObject\u5bf9\u8c61\u53ea\u6709\u4e00\u4e2a\u3002<\/p>\n<p>\u8bf4\u4e00\u4e2a\u5bb9\u6613\u5ffd\u7565\u7684\u95ee\u9898\uff0cimport\u53ea\u80fd\u5bfc\u5165\u6a21\u5757\uff0c\u4e0d\u80fd\u5bfc\u5165\u6a21\u5757\u4e2d\u7684\u5bf9\u8c61\uff08\u7c7b\u3001\u51fd\u6570\u3001\u53d8\u91cf\u7b49\uff09\u3002\u5982\u4e00\u4e2a\u6a21\u5757A\uff08A.py\uff09\u4e2d\u6709\u4e2a\u51fd\u6570getName\uff0c\u53e6\u4e00\u4e2a\u6a21\u5757\u4e0d\u80fd\u901a\u8fc7import A.getName\u5c06getName\u5bfc\u5165\u5230\u672c\u6a21\u5757\uff0c\u53ea\u80fd\u7528import A\u3002\u5982\u679c\u60f3\u53ea\u5bfc\u5165\u7279\u5b9a\u7684\u7c7b\u3001\u51fd\u6570\u3001\u53d8\u91cf\u5219\u7528from A import getName\u5373\u53ef\u3002<\/p>\n<p>\u5d4c\u5957Import<\/p>\n<p>\u5d4c\u5957import\uff0c\u6211\u5206\u4e24\u79cd\u60c5\u51b5\uff0c\u4e00\u79cd\u662f\uff1a\u672c\u6a21\u5757\u5bfc\u5165A\u6a21\u5757\uff08import A\uff09\uff0c\u800cA\u4e2d\u53c8\u6709import\u8bed\u53e5\uff0c\u4f1a\u6fc0\u6d3b\u53e6\u4e00\u4e2aimport\u52a8\u4f5c\uff0c\u5982import B\uff0c\u800cB\u6a21\u5757\u53c8\u53ef\u4ee5import\u5176\u4ed6\u6a21\u5757\uff0c\u4e00\u76f4\u4e0b\u53bb\u3002<\/p>\n<p>\u5bf9\u8fd9\u79cd\u5d4c\u5957\u6bd4\u8f83\u5bb9\u6613\u7406\u89e3\uff0c\u6ce8\u610f\u4e00\u70b9\u5c31\u662f\u5404\u4e2a\u6a21\u5757\u7684Local\u540d\u5b57\u7a7a\u95f4\u662f\u72ec\u7acb\u7684\uff0c\u6240\u4ee5\u4e0a\u9762\u7684\u4f8b\u5b50\uff0c\u672c\u6a21\u5757import A\u5b8c\u4e86\u540e\u672c\u6a21\u5757\u53ea\u80fd\u8bbf\u95ee\u6a21\u5757A\uff0c\u4e0d\u80fd\u8bbf\u95eeB\u53ca\u5176\u4ed6\u6a21\u5757\u3002\u867d\u7136\u6a21\u5757B\u5df2\u7ecf\u52a0\u8f7d\u5230\u5185\u5b58\u4e86\uff0c\u5982\u679c\u8981\u8bbf\u95ee\u8fd8\u8981\u5728\u660e\u786e\u7684\u5728\u672c\u6a21\u5757\u4e2dimport B\u3002<\/p>\n<p>\u53e6\u5916\u4e00\u79cd\u5d4c\u5957\u6307\uff0c\u5728\u6a21\u5757A\u4e2dimport B\uff0c\u800c\u5728\u6a21\u5757B\u4e2dimport A\u3002\u8fd9\u65f6\u4f1a\u600e\u4e48\u6837\u5462\uff1f\u8fd9\u4e2a\u5728Python\u5217\u8868\u4e2d\u7531RobertChen\u7ed9\u51fa\u4e86\u8be6\u7ec6\u89e3\u91ca\uff0c\u6284\u5f55\u5982\u4e0b\uff1a<\/p>\n<p>[A.py] from B import D class C:pass [B.py] from A import C class D:pass<\/p>\n<p>\u4e3a\u4ec0\u4e48\u6267\u884cA\u7684\u65f6\u5019\u4e0d\u80fd\u52a0\u8f7dD\u5462\uff1f <\/p>\n<p>\u5982\u679c\u5c06A.py\u6539\u4e3a\uff1aimport B\u5c31\u53ef\u4ee5\u4e86\u3002 <\/p>\n<p>\u8fd9\u662f\u600e\u4e48\u56de\u4e8b\u5462\uff1f <\/p>\n<p>RobertChen\uff1a\u8fd9\u8ddfPython\u5185\u90e8import\u7684\u673a\u5236\u662f\u6709\u5173\u7684\uff0c\u5177\u4f53\u5230from B import D\uff0cPython\u5185\u90e8\u4f1a\u5206\u6210\u51e0\u4e2a\u6b65\u9aa4\uff1a <\/p>\n<ol>\n<li>\u5728sys.modules\u4e2d\u67e5\u627e\u7b26\u53f7&quot;B&quot; <\/li>\n<li>\u679c\u7b26\u53f7B\u5b58\u5728\uff0c\u5219\u83b7\u5f97\u7b26\u53f7B\u5bf9\u5e94\u7684module\u5bf9\u8c61&lt;module B&gt;\u3002\n<p>\u4ece&lt;module B&gt;\u7684__dict__\u4e2d\u83b7\u5f97\u7b26\u53f7&quot;D&quot;\u5bf9\u5e94\u7684\u5bf9\u8c61\uff0c\u5982\u679c&quot;D&quot;\u4e0d\u5b58\u5728\uff0c\u5219\u629b\u51fa\u5f02\u5e38 <\/p>\n<\/li>\n<li>\n<p>\u5982\u679c\u7b26\u53f7B\u4e0d\u5b58\u5728\uff0c\u5219\u521b\u5efa\u4e00\u4e2a\u65b0\u7684module\u5bf9\u8c61&lt;module B&gt;\uff0c\u6ce8\u610f\uff0c\u8fd9\u65f6\uff0cmodule\u5bf9\u8c61\u7684__dict__\u4e3a\u7a7a\u3002\u6267\u884cB.py\u4e2d\u7684\u8868\u8fbe\u5f0f\uff0c\u586b\u5145&lt;module B&gt;\u7684__dict__ \u3002 <\/p>\n<p>\u4ece&lt;module B&gt;\u7684__dict__\u4e2d\u83b7\u5f97&quot;D&quot;\u5bf9\u5e94\u7684\u5bf9\u8c61\uff0c\u5982\u679c&quot;D&quot;\u4e0d\u5b58\u5728\uff0c\u5219\u629b\u51fa\u5f02\u5e38\u3002<\/p>\n<\/li>\n<\/ol>\n<p>\u6240\u4ee5\uff0c\u8fd9\u4e2a\u4f8b\u5b50\u7684\u6267\u884c\u987a\u5e8f\u5982\u4e0b\uff1a <\/p>\n<p>1\u3001\u6267\u884cA.py\u4e2d\u7684from B import D<\/p>\n<p>\u7531\u4e8e\u662f\u6267\u884c\u7684python A.py\uff0c\u6240\u4ee5\u5728sys.modules\u4e2d\u5e76\u6ca1\u6709&lt;module B&gt;\u5b58\u5728\uff0c\u9996\u5148\u4e3aB.py\u521b\u5efa\u4e00\u4e2amodule\u5bf9\u8c61(&lt;module B&gt;)\uff0c\u6ce8\u610f\uff0c\u8fd9\u65f6\u521b\u5efa\u7684\u8fd9\u4e2amodule\u5bf9\u8c61\u662f\u7a7a\u7684\uff0c\u91cc\u8fb9\u5565\u4e5f\u6ca1\u6709\uff0c\u5728Python\u5185\u90e8\u521b\u5efa\u4e86\u8fd9\u4e2amodule\u5bf9\u8c61\u4e4b\u540e\uff0c\u5c31\u4f1a\u89e3\u6790\u6267\u884cB.py\uff0c\u5176\u76ee\u7684\u662f\u586b\u5145&lt;module B&gt;\u8fd9\u4e2adict\u3002<\/p>\n<p>2\u3001\u6267\u884cB.py\u4e2d\u7684from A import C<\/p>\n<p>\u5728\u6267\u884cB.py\u7684\u8fc7\u7a0b\u4e2d\uff0c\u4f1a\u78b0\u5230\u8fd9\u4e00\u53e5\uff0c\u9996\u5148\u68c0\u67e5sys.modules\u8fd9\u4e2amodule\u7f13\u5b58\u4e2d\u662f\u5426\u5df2\u7ecf\u5b58\u5728&lt;module A&gt;\u4e86\uff0c\u7531\u4e8e\u8fd9\u65f6\u7f13\u5b58\u8fd8\u6ca1\u6709\u7f13\u5b58&lt;module A&gt;\uff0c\u6240\u4ee5\u7c7b\u4f3c\u7684\uff0cPython\u5185\u90e8\u4f1a\u4e3aA.py\u521b\u5efa\u4e00\u4e2amodule\u5bf9\u8c61(&lt;module A&gt;)\uff0c\u7136\u540e\uff0c\u540c\u6837\u5730\uff0c\u6267\u884cA.py\u4e2d\u7684\u8bed\u53e5\u3002<\/p>\n<p>3\u3001\u518d\u6b21\u6267\u884cA.py\u4e2d\u7684from B import D<\/p>\n<p>\u8fd9\u65f6\uff0c\u7531\u4e8e\u5728\u7b2c1\u6b65\u65f6\uff0c\u521b\u5efa\u7684&lt;module B&gt;\u5bf9\u8c61\u5df2\u7ecf\u7f13\u5b58\u5728\u4e86sys.modules\u4e2d\uff0c\u6240\u4ee5\u76f4\u63a5\u5c31\u5f97\u5230\u4e86&lt;module B&gt;\uff0c\u4f46\u662f\uff0c\u6ce8\u610f\uff0c\u4ece\u6574\u4e2a\u8fc7\u7a0b\u6765\u770b\uff0c\u6211\u4eec\u77e5\u9053\uff0c\u8fd9\u65f6&lt;module B&gt;\u8fd8\u662f\u4e00\u4e2a\u7a7a\u7684\u5bf9\u8c61\uff0c\u91cc\u9762\u5565\u4e5f\u6ca1\u6709\uff0c\u6240\u4ee5\u4ece\u8fd9\u4e2amodule\u4e2d\u83b7\u5f97\u7b26\u53f7&quot;D&quot;\u7684\u64cd\u4f5c\u5c31\u4f1a\u629b\u51fa\u5f02\u5e38\u3002\u5982\u679c\u8fd9\u91cc\u53ea\u662fimport B\uff0c\u7531\u4e8e&quot;B&quot;\u8fd9\u4e2a\u7b26\u53f7\u5728sys.modules\u4e2d\u5df2\u7ecf\u5b58\u5728\uff0c\u6240\u4ee5\u662f\u4e0d\u4f1a\u629b\u51fa\u5f02\u5e38\u7684\u3002<\/p>\n<p>\u4e0a\u9762\u7684\u89e3\u91ca\u5df2\u7ecf\u7531Zoom.Quiet\u6536\u5f55\u5728<a href=\"http:\/\/wiki.woodpecker.org.cn\/moin\/MiscItems\/2008-11-25\">\u5544\u6728\u9e1f<\/a>\u4e86\uff0c\u91cc\u9762\u6709\u56fe\uff0c\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p>Package\uff08\u5305\uff09 Import<\/p>\n<p>\u5305\uff08Package\uff09\u53ef\u4ee5\u770b\u6210\u6a21\u5757\u7684\u96c6\u5408\uff0c\u53ea\u8981\u4e00\u4e2a\u6587\u4ef6\u5939\u4e0b\u9762\u6709\u4e2a__init__.py\u6587\u4ef6\uff0c\u90a3\u4e48\u8fd9\u4e2a\u6587\u4ef6\u5939\u5c31\u53ef\u4ee5\u770b\u505a\u662f\u4e00\u4e2a\u5305\u3002\u5305\u4e0b\u9762\u7684\u6587\u4ef6\u5939\u8fd8\u53ef\u4ee5\u6210\u4e3a\u5305\uff08\u5b50\u5305\uff09\u3002\u66f4\u8fdb\u4e00\u6b65\uff0c\u591a\u4e2a\u8f83\u5c0f\u7684\u5305\u53ef\u4ee5\u805a\u5408\u6210\u4e00\u4e2a\u8f83\u5927\u7684\u5305\uff0c\u901a\u8fc7\u5305\u8fd9\u79cd\u7ed3\u6784\uff0c\u65b9\u4fbf\u4e86\u7c7b\u7684\u7ba1\u7406\u548c\u7ef4\u62a4\uff0c\u4e5f\u65b9\u4fbf\u4e86\u7528\u6237\u7684\u4f7f\u7528\u3002\u6bd4\u5982SQLAlchemy\u7b49\u90fd\u662f\u4ee5\u5305\u7684\u5f62\u5f0f\u53d1\u5e03\u7ed9\u7528\u6237\u7684\u3002<\/p>\n<p>\u5305\u548c\u6a21\u5757\u5176\u5b9e\u662f\u5f88\u7c7b\u4f3c\u7684\u4e1c\u897f\uff0c\u5982\u679c\u67e5\u770b\u5305\u7684\u7c7b\u578bimport SQLAlchemy type(SQLAlchemy)\uff0c\u53ef\u4ee5\u770b\u5230\u5176\u5b9e\u4e5f\u662f&lt;type &#8216;module&#8217;&gt;\u3002import\u5305\u7684\u65f6\u5019\u67e5\u627e\u7684\u8def\u5f84\u4e5f\u662fsys.path\u3002<\/p>\n<p>\u5305\u5bfc\u5165\u7684\u8fc7\u7a0b\u548c\u6a21\u5757\u7684\u57fa\u672c\u4e00\u81f4\uff0c\u53ea\u662f\u5bfc\u5165\u5305\u7684\u65f6\u5019\u4f1a\u6267\u884c\u6b64\u5305\u76ee\u5f55\u4e0b\u7684__init__.py\u800c\u4e0d\u662f\u6a21\u5757\u91cc\u9762\u7684\u8bed\u53e5\u4e86\u3002\u53e6\u5916\uff0c\u5982\u679c\u53ea\u662f\u5355\u7eaf\u7684\u5bfc\u5165\u5305\uff0c\u800c\u5305\u7684__init__.py\u4e2d\u53c8\u6ca1\u6709\u660e\u786e\u7684\u5176\u4ed6\u521d\u59cb\u5316\u64cd\u4f5c\uff0c\u90a3\u4e48\u6b64\u5305\u4e0b\u9762\u7684\u6a21\u5757\u662f\u4e0d\u4f1a\u81ea\u52a8\u5bfc\u5165\u7684\u3002\u5982\uff1a<\/p>\n<p>PA<\/p>\n<p>&#8211;__init__.py<\/p>\n<p>&#8211;wave.py<\/p>\n<p>&#8211;PB1<\/p>\n<p>&#160; &#8211;__init__.py<\/p>\n<p>&#160; &#8211;pb1_m.py<\/p>\n<p>&#8211;PB2<\/p>\n<p>&#160; &#8211;__init__.py<\/p>\n<p>&#160; &#8211;pb2_m.py<\/p>\n<p>__init__.py\u90fd\u4e3a\u7a7a\uff0c\u5982\u679c\u6709\u4ee5\u4e0b\u7a0b\u5e8f\uff1a<\/p>\n<ol>\n<li>import sys <\/li>\n<li>import PA.wave&#160; #1 <\/li>\n<li>import PA.PB1&#160;&#160; #2 <\/li>\n<li>import PA.PB1.pb1_m as m1&#160; #3 <\/li>\n<li><\/li>\n<li>import PA.PB2.pb2_m #4 <\/li>\n<li><\/li>\n<li>PA.wave.getName() #5 <\/li>\n<li><\/li>\n<li>m1.getName() #6 <\/li>\n<li><\/li>\n<li>PA.PB2.pb2_m.getName() #7<\/li>\n<\/ol>\n<p>\u5f53\u6267\u884c#1\u540e\uff0csys.modules\u4f1a\u540c\u65f6\u5b58\u5728PA\u3001PA.wave\u4e24\u4e2a\u6a21\u5757\uff0c\u6b64\u65f6\u53ef\u4ee5\u8c03\u7528PA.wave\u7684\u4efb\u4f55\u7c7b\u6216\u51fd\u6570\u4e86\u3002\u4f46\u4e0d\u80fd\u8c03\u7528PA.PB1(2)\u4e0b\u7684\u4efb\u4f55\u6a21\u5757\u3002\u5f53\u524dLocal\u4e2d\u6709\u4e86PA\u540d\u5b57\u3002<\/p>\n<p>\u5f53\u6267\u884c#2\u540e\uff0c\u53ea\u662f\u5c06PA.PB1\u8f7d\u5165\u5185\u5b58\uff0csys.modules\u4e2d\u4f1a\u6709PA\u3001PA.wave\u3001PA.PB1\u4e09\u4e2a\u6a21\u5757\uff0c\u4f46\u662fPA.PB1\u4e0b\u7684\u4efb\u4f55\u6a21\u5757\u90fd\u6ca1\u6709\u81ea\u52a8\u8f7d\u5165\u5185\u5b58\uff0c\u6b64\u65f6\u5982\u679c\u76f4\u63a5\u6267\u884cPA.PB1.pb1_m.getName()\u5219\u4f1a\u51fa\u9519\uff0c\u56e0\u4e3aPA.PB1\u4e2d\u5e76\u6ca1\u6709pb1_m\u3002\u5f53\u524dLocal\u4e2d\u8fd8\u662f\u53ea\u6709PA\u540d\u5b57\uff0c\u5e76\u6ca1\u6709PA.PB1\u540d\u5b57\u3002<\/p>\n<p>\u5f53\u6267\u884c#3\u540e\uff0c\u4f1a\u5c06PA.PB1\u4e0b\u7684pb1_m\u8f7d\u5165\u5185\u5b58\uff0csys.modules\u4e2d\u4f1a\u6709PA\u3001PA.wave\u3001PA.PB1\u3001PA.PB1.pb1_m\u56db\u4e2a\u6a21\u5757\uff0c\u6b64\u65f6\u53ef\u4ee5\u6267\u884cPA.PB1.pb1_m.getName()\u4e86\u3002\u7531\u4e8e\u4f7f\u7528\u4e86as\uff0c\u5f53\u524dLocal\u4e2d\u9664\u4e86PA\u540d\u5b57\uff0c\u53e6\u5916\u6dfb\u52a0\u4e86m1\u4f5c\u4e3aPA.PB1.pb1_m\u7684\u522b\u540d\u3002<\/p>\n<p>\u5f53\u6267\u884c#4\u540e\uff0c\u4f1a\u5c06PA.PB2\u3001PA.PB2.pb2_m\u8f7d\u5165\u5185\u5b58\uff0csys.modules\u4e2d\u4f1a\u6709PA\u3001PA.wave\u3001PA.PB1\u3001PA.PB1.pb1_m\u3001PA.PB2\u3001PA.PB2.pb2_m\u516d\u4e2a\u6a21\u5757\u3002\u5f53\u524dLocal\u4e2d\u8fd8\u662f\u53ea\u6709PA\u3001m1\u3002<\/p>\n<p>\u4e0b\u9762\u7684#5\uff0c#6\uff0c#7\u90fd\u662f\u53ef\u4ee5\u6b63\u786e\u8fd0\u884c\u7684\u3002<\/p>\n<p>\u6ce8\u610f\u7684\u662f\uff1a\u5982\u679cPA.PB2.pb2_m\u60f3\u5bfc\u5165PA.PB1.pb1_m\u3001PA.wave\u662f\u53ef\u4ee5\u76f4\u63a5\u6210\u529f\u7684\u3002\u6700\u597d\u662f\u91c7\u7528\u660e\u786e\u7684\u5bfc\u5165\u8def\u5f84\uff0c\u5bf9\u4e8e.\/..\u76f8\u5bf9\u5bfc\u5165\u8def\u5f84\u8fd8\u662f\u4e0d\u63a8\u8350\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6a21\u5757\u7684\u641c\u7d22\u8def\u5f84 \u6a21\u5757\u7684\u641c\u7d22\u8def\u5f84\u90fd\u653e\u5728\u4e86sys.path\u5217\u8868\u4e2d&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[104],"tags":[],"class_list":["post-1065","post","type-post","status-publish","format-standard","hentry","category-technogy"],"_links":{"self":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/1065","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1065"}],"version-history":[{"count":0,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=\/wp\/v2\/posts\/1065\/revisions"}],"wp:attachment":[{"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1065"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1065"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fanhaijun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1065"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}