{"id":205137,"date":"2025-05-29T09:31:18","date_gmt":"2025-05-29T01:31:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/205137\/"},"modified":"2025-05-29T09:31:18","modified_gmt":"2025-05-29T01:31:18","slug":"%e5%9c%a8-python-%e4%b8%ad%e7%ae%a1%e7%90%86%e5%af%bc%e5%85%a5%ef%bc%9a%e4%bd%bf%e7%94%a8-importspy-%e4%b8%bb%e5%8a%a8%e9%aa%8c%e8%af%81%e7%9a%84%e9%87%8d%e8%a6%81%e6%80%a7","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/205137\/","title":{"rendered":"\u5728 Python \u4e2d\u7ba1\u7406\u5bfc\u5165\uff1a\u4f7f\u7528 ImportSpy \u4e3b\u52a8\u9a8c\u8bc1\u7684\u91cd\u8981\u6027"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5728 Python \u4e2d\u7ba1\u7406\u5bfc\u5165\uff1a\u4f7f\u7528 ImportSpy \u4e3b\u52a8\u9a8c\u8bc1\u7684\u91cd\u8981\u6027<\/h1>\n<p>\u600e\u4e48\u5165\u95e8\u6587\u7ae0\u7f16\u7a0b\uff1f\u9700\u8981\u5b66\u4e60\u54ea\u4e9b\u77e5\u8bc6\u70b9\uff1f\u8fd9\u662f\u65b0\u624b\u4eec\u521a\u63a5\u89e6\u7f16\u7a0b\u65f6\u5e38\u89c1\u7684\u95ee\u9898\uff1b\u4e0b\u9762\u5c31\u6765\u7ed9\u5927\u5bb6\u6574\u7406\u5206\u4eab\u4e00\u4e9b\u77e5\u8bc6\u70b9\uff0c\u5e0c\u671b\u80fd\u591f\u7ed9\u521d\u5b66\u8005\u4e00\u4e9b\u5e2e\u52a9\u3002\u672c\u7bc7\u6587\u7ae0\u5c31\u6765\u4ecb\u7ecd\u300a\u5728 Python \u4e2d\u7ba1\u7406\u5bfc\u5165\uff1a\u4f7f\u7528 ImportSpy \u4e3b\u52a8\u9a8c\u8bc1\u7684\u91cd\u8981\u6027\u300b\uff0c\u6d89\u53ca\u5230\uff0c\u6709\u9700\u8981\u7684\u53ef\u4ee5\u6536\u85cf\u4e00\u4e0b<\/p>\n<p>\u5728\u5f00\u53d1\u6253\u7b97\u7531\u5916\u90e8\u4ee3\u7801\u5bfc\u5165\u7684 python \u6a21\u5757\u65f6\uff0c<strong>\u786e\u4fdd\u6b64\u7c7b\u5bfc\u5165\u7b26\u5408\u7279\u5b9a\u8981\u6c42<\/strong>\u81f3\u5173\u91cd\u8981\u3002\u672a\u80fd\u6b63\u786e\u7ba1\u7406\u5bfc\u5165\u53ef\u80fd\u4f1a\u5bfc\u81f4\u51b2\u7a81\u3001\u9519\u8bef\u4ee5\u53ca\u5f00\u53d1\u548c\u7ef4\u62a4\u65b9\u9762\u7684\u91cd\u5927\u6311\u6218\u3002 importspy \u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684 python \u5e93\uff0c\u5141\u8bb8\u5f00\u53d1\u4eba\u5458<strong>\u4e3b\u52a8\u7ba1\u7406\u5bfc\u5165\uff0c\u786e\u4fdd\u5916\u90e8\u6a21\u5757\u9075\u5b88\u4ee3\u7801\u6240\u9700\u7684\u9884\u5b9a\u4e49\u7ed3\u6784\u548c\u89c4\u5219<\/strong>\u3002<\/p>\n<p>\u8981\u4e86\u89e3\u5229\u7528 importspy<strong> \u786e\u4fdd\u6b63\u786e\u63a7\u5236\u5bfc\u5165\u7684\u9879\u76ee\u7684<\/strong>\u6700\u5c0f\u67b6\u6784\uff0c\u8bf7\u53c2\u8003\u4e0b\u56fe\uff1a<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241124\/17324357966742df54d4a35.jpg\" class=\"aligncenter\"><\/p>\n<p>\u6b64\u56fe\u8bf4\u660e\u4e86\u5f53\u5916\u90e8\u6a21\u5757\u5c1d\u8bd5\u5bfc\u5165\u60a8\u7684\u6a21\u5757\u5e76\u63a5\u53d7 importspy \u9a8c\u8bc1\u65f6\u6240\u6d89\u53ca\u7684\u5173\u952e\u7ec4\u4ef6\u548c\u4ea4\u4e92\uff1a<\/p>\n<p>1.<strong>\u60a8\u7684\u6a21\u5757<\/strong>\uff1a\u8fd9\u4ee3\u8868\u60a8\u5f00\u53d1\u7684\u4ee3\u7801\uff0c\u5c06\u7531\u5916\u90e8\u6a21\u5757\u5bfc\u5165\u3002\u8be5\u6a21\u5757\u53d7\u5230 importspy \u7684\u201c\u4fdd\u62a4\u201d\uff0c\u4ee5\u786e\u4fdd\u6b63\u786e\u4f7f\u7528\u3002<br \/> 2.<strong>\u5916\u90e8\u6a21\u5757<\/strong>\uff1a\u8fd9\u662f\u5c1d\u8bd5\u5bfc\u5165\u6a21\u5757\u4ee5\u4f7f\u7528\u5176\u529f\u80fd\u7684\u5916\u90e8\u4ee3\u7801\u3002\u5916\u90e8\u6a21\u5757\u5fc5\u987b\u9075\u5b88\u4e00\u5b9a\u7684\u7ed3\u6784\u89c4\u5219\u624d\u80fd\u6210\u529f\u5b8c\u6210\u5bfc\u5165\u8fc7\u7a0b\u3002<br \/> 3.<strong>importspy<\/strong>\uff1a\u4f5c\u4e3a\u4ee3\u7801\u7684\u5b88\u62a4\u8005\uff0cimportspy \u62e6\u622a\u5bfc\u5165\u5c1d\u8bd5\u5e76\u68c0\u67e5\u5916\u90e8\u6a21\u5757\u662f\u5426\u9075\u5faa\u5f00\u53d1\u4eba\u5458\u6307\u5b9a\u7684\u89c4\u5219\uff08\u4f7f\u7528 spymodel\uff09\u3002\u5982\u679c\u5916\u90e8\u6a21\u5757\u4e0d\u7b26\u5408\u8981\u6c42\uff0c\u5bfc\u5165\u5c06\u88ab\u963b\u6b62\u3002<\/p>\n<p>\u901a\u8fc7\u6267\u884c\u8fd9\u4e9b\u89c4\u5219\uff0cimportspy \u964d\u4f4e\u4e86\u51b2\u7a81\u3001\u4e0d\u5f53\u4f7f\u7528\u4ee5\u53ca\u56e0\u5bfc\u5165\u7ed3\u6784\u4e0d\u6b63\u786e\u7684\u4ee3\u7801\u800c\u4ea7\u751f\u7684\u9519\u8bef\u7684\u98ce\u9669\u3002<\/p>\n<p>\u56fe\u4e2d\u63cf\u8ff0\u7684\u8fc7\u7a0b\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<ol>\n<li> <strong>\u5bfc\u5165\u5c1d\u8bd5<\/strong>\uff1a\u5916\u90e8\u6a21\u5757<strong>\u5c1d\u8bd5\u5bfc\u5165<\/strong>\u60a8\u7684\u6a21\u5757\u3002<\/li>\n<li> <strong>\u62e6\u622a\u548c\u9a8c\u8bc1<\/strong>\uff1aimportspy \u7acb\u5373<strong>\u62e6\u622a<\/strong>\u5bfc\u5165\u8fc7\u7a0b\uff0c<strong>\u68c0\u67e5<\/strong>\u5916\u90e8\u6a21\u5757\u662f\u5426\u7b26\u5408\u6240\u6709\u5b9a\u4e49\u7684\u89c4\u5219\u3002\u8fd9\u4e9b\u89c4\u5219\u53ef\u80fd\u5305\u62ec\u7279\u5b9a\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u7684\u5b58\u5728\uff0c\u5b83\u4eec\u662f\u6839\u636e\u4f7f\u7528 spymodel \u521b\u5efa\u7684<strong>\u9a8c\u8bc1\u6a21\u578b<\/strong>\u6784\u5efa\u7684\u3002<\/li>\n<li> <strong>\u6279\u51c6\u6216\u62d2\u7edd<\/strong>\uff1a\u5982\u679c\u5916\u90e8\u6a21\u5757\u6ee1\u8db3\u8981\u6c42\uff0c\u5219\u5bfc\u5165<strong>\u6210\u529f<\/strong>\uff0c\u5e76\u4e14\u8be5\u6a21\u5757\u5df2\u96c6\u6210\u5230\u9879\u76ee\u4e2d\u3002\u5982\u679c\u5931\u8d25\uff0cimportspy <strong>\u4f1a\u963b\u6b62\u5bfc\u5165<\/strong> \u5e76\u8fd4\u56de\u4e00\u4e2a\u9519\u8bef\uff0c\u7a81\u51fa\u663e\u793a\u4e0d\u5408\u89c4\u60c5\u51b5\u3002<\/li>\n<\/ol>\n<p>importspy \u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5b9a\u4e49\u5916\u90e8\u6a21\u5757\u5fc5\u987b\u9075\u5faa\u7684\u6e05\u6670\u4e14\u4e25\u683c\u7684\u7ed3\u6784\u624d\u80fd\u4f7f\u7528\u5176\u529f\u80fd\u3002\u4f7f\u7528 <strong>spymodel<\/strong> \u7c7b\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u6307\u5b9a\uff1a<\/p>\n<ul>\n<li> <strong>\u5fc5\u9700\u53d8\u91cf<\/strong>\uff1a\u5fc5\u987b\u5728\u5916\u90e8\u6a21\u5757\u4e2d\u5b9a\u4e49\u7684\u53d8\u91cf\u3002<\/li>\n<li> <strong>\u5fc5\u8981\u529f\u80fd<\/strong>\uff1a\u5bfc\u5165\u6a21\u5757\u5fc5\u987b\u5b9e\u73b0\u7684\u529f\u80fd\u3002<\/li>\n<li> <strong>\u7c7b\u548c\u65b9\u6cd5<\/strong>\uff1a\u5916\u90e8\u6a21\u5757\u4e2d\u5fc5\u987b\u5b58\u5728\u7684\u5fc5\u9700\u7c7b\u53ca\u5176\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n<p>\u5f53\u5916\u90e8\u6a21\u5757\u5c1d\u8bd5\u5bfc\u5165\u60a8\u7684\u4ee3\u7801\u65f6\uff0cimportspy \u4f1a\u5c06\u5bfc\u5165\u7684\u6a21\u5757\u4e0e\u5f00\u53d1\u4eba\u5458\u4f7f\u7528 spymodel \u5b9a\u4e49\u7684\u7ed3\u6784\u8fdb\u884c\u6bd4\u8f83\u548c\u9a8c\u8bc1\u3002\u9a8c\u8bc1\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li> <strong>\u6a21\u578b\u5b9a\u4e49<\/strong>\uff1a\u5f00\u53d1\u4eba\u5458\u4f7f\u7528 spymodel \u5b9a\u4e49\u9a8c\u8bc1\u6a21\u578b\uff0c\u6307\u5b9a\u6240\u9700\u7684\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u3002\u8be5\u6a21\u578b\u5145\u5f53\u5916\u90e8\u6a21\u5757\u5fc5\u987b\u9075\u5faa\u7684\u4e00\u7ec4\u89c4\u5219\u3002<\/li>\n<li> <strong>\u4e00\u81f4\u6027\u68c0\u67e5<\/strong>\uff1aimportspy \u5728\u5c06\u5916\u90e8\u6a21\u5757\u4e0e\u9a8c\u8bc1\u6a21\u578b\u8fdb\u884c\u6bd4\u8f83\u65f6\u5e94\u7528\u5b50\u96c6\u903b\u8f91\u3002\u5b83\u68c0\u67e5\u5bfc\u5165\u7684\u6a21\u5757\u662f\u5426\u5305\u542b spymodel \u4e2d\u5b9a\u4e49\u7684\u6240\u6709\u5fc5\u9700\u5143\u7d20\uff08\u53d8\u91cf\u3001\u51fd\u6570\u3001\u7c7b\uff09\u3002<\/li>\n<li> <strong>\u9519\u8bef\u5904\u7406<\/strong>\uff1a\u5982\u679c\u5bfc\u5165\u7684\u6a21\u5757\u7f3a\u5c11\u4efb\u4f55\u5fc5\u9700\u7684\u5143\u7d20\u6216\u5305\u542b\u7ed3\u6784\u5dee\u5f02\uff0cimportspy \u4f1a\u5f15\u53d1\u9519\u8bef\uff0c\u4ece\u800c\u963b\u6b62\u5bfc\u5165\u3002\u8fd9\u786e\u4fdd\u4e86\u4ee3\u7801\u7684\u6b63\u786e\u4f7f\u7528\uff0c\u51cf\u5c11\u4e86\u51b2\u7a81\u548c\u4e0d\u53ef\u9884\u89c1\u884c\u4e3a\u7684\u98ce\u9669\u3002<\/li>\n<\/ol>\n<p>\u5206\u6790 importspy \u7684 github \u5b58\u50a8\u5e93\u4e2d\u7684\u4ee3\u7801\u63ed\u793a\u4e86\u4e00\u4e9b\u57fa\u672c\u529f\u80fd\uff1a<\/p>\n<ol>\n<li> <strong>\u4e3b\u52a8\u9a8c\u8bc1<\/strong>\uff1aspymodel \u7c7b\u4e0d\u4ec5\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u4e3a\u65b0\u6a21\u5757\u5b9a\u4e49\u89c4\u5219\uff0c\u8fd8\u53ef\u4ee5\u8ffd\u6eaf\u9a8c\u8bc1\u73b0\u6709\u4ee3\u7801\u3002\u8fd9\u5bf9\u4e8e\u5728\u521d\u59cb\u5f00\u53d1\u671f\u95f4\u53ef\u80fd\u672a\u8003\u8651\u9a8c\u8bc1\u7684\u9057\u7559\u9879\u76ee\u7279\u522b\u6709\u7528\u3002<\/li>\n<li> <strong>\u4f9d\u8d56\u5173\u7cfb\u68c0\u6d4b<\/strong>\uff1aimportspy \u81ea\u52a8\u68c0\u67e5\u5bfc\u5165\u6a21\u5757\u662f\u5426\u9075\u5faa\u9884\u5b9a\u4e49\u7684\u7ed3\u6784\uff0c\u5305\u62ec\u6587\u4ef6\u540d\u3001\u7248\u672c\u3001\u51fd\u6570\u548c\u7c7b\u3002\u8fd9\u6709\u52a9\u4e8e\u7ef4\u62a4\u9879\u76ee\u4e2d\u4f9d\u8d56\u5173\u7cfb\u7684\u5b8c\u6574\u6027\u3002<\/li>\n<li> <strong>\u63d2\u4ef6\u9694\u79bb<\/strong>\uff1aimportspy \u5728\u57fa\u4e8e\u63d2\u4ef6\u7684\u67b6\u6784\u4e2d\u7279\u522b\u6709\u7528\uff0c\u5176\u4e2d\u6a21\u5757\u5fc5\u987b\u5728\u96c6\u6210\u4e4b\u524d\u8fdb\u884c\u9694\u79bb\u548c\u9a8c\u8bc1\u3002\u8fd9\u786e\u4fdd\u4e86\u6574\u4e2a\u7cfb\u7edf\u4fdd\u6301\u6a21\u5757\u5316\u548c\u7a33\u5b9a\u3002<\/li>\n<\/ol>\n<p>importspy \u5165\u95e8\u5f88\u7b80\u5355\uff0c\u53ef\u4ee5\u901a\u8fc7 pip \u5b8c\u6210\uff1a<\/p>\n<pre>pip install importspy\n<\/pre>\n<p>\u5b89\u88c5\u540e\uff0c\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u5728\u5176\u4ee3\u7801\u4e2d\u914d\u7f6e importspy\uff0c\u4ee5\u4f7f\u7528 <strong>spymodel \u7c7b<\/strong>.<\/p>\n<p> \u5b9a\u4e49\u5fc5\u8981\u7684\u5bfc\u5165\u89c4\u5219 <\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528\u793a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u4f7f\u7528 importspy \u6765\u9a8c\u8bc1\u5bfc\u5165\u7684\u6a21\u5757\u3002\u5b83\u5305\u62ec\u4e3b\u6a21\u5757\u548c\u5916\u90e8\u6a21\u5757\u7684\u4ee3\u7801\uff0c\u5fc5\u987b\u9075\u5b88\u5f00\u53d1\u4eba\u5458\u8bbe\u5b9a\u7684\u89c4\u5219\u3002<\/p>\n<p><strong>\u4e3b\u6a21\u5757<\/strong>\u4ee3\u7801\uff1ayour_code.py<\/p>\n<pre>from importspy import spy\nfrom importspy.models import spymodel, classmodel\nfrom typing import list\n\n# define the rules for the structure and usage of your python code by external modules\nclass mylibraryspy(spymodel):\n    # list of required variables that must be present in the importing module\n    variables: list[str] = [\"required_var1\", \"required_var2\"]\n\n    # list of required functions that must be defined in the importing module\n    functions: list[str] = [\"required_function\"]\n\n    # define the required classes, their attributes, and methods\n    classes: list[classmodel] = [\n        classmodel(\n            name=\"myrequiredclass\",\n            class_attr=[\"attr_1\", \"attr_2\"],  # class-level attributes\n            instance_attr=[\"attr_3\"],         # instance-level attributes\n            methods=[\"required_method1\", \"required_method2\"]  # required methods\n        )\n    ]\n\n# use importspy to check if the importing module complies with the defined rules\nmodule = spy().importspy(spymodel=mylibraryspy)\n\nif module:\n    print(f\"module '{module.__name__}' complies with the specified rules and is ready to use!\")\nelse:\n    print(\"the importing module does not comply with the required structure.\")\n<\/pre>\n<p>\u5728\u672c\u6a21\u5757\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u6240\u9700\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u7ed3\u6784\u7684\u89c4\u5219\u3002 importspy \u786e\u4fdd\u5bfc\u5165\u6a21\u5757\u9075\u5b88\u8fd9\u4e9b\u89c4\u5219\u3002<\/p>\n<p><strong>\u5916\u90e8\u6a21\u5757<\/strong>\u4ee3\u7801\uff1aimporting_module.py<\/p>\n<pre>import your_code\n\n# Define the required variables at the module level\nrequired_var1 = \"Value for required_var1\"\nrequired_var2 = \"Value for required_var2\"\n\n# Define the required class as per the validation model\nclass MyRequiredClass:\n    # Class-level attributes\n    attr_1 = \"Class attribute 1\"\n    attr_2 = \"Class attribute 2\"\n\n    # Instance-level attributes\n    def __init__(self):\n        self.attr_3 = \"Instance attribute\"\n\n    # Implement the required methods\n    def required_method1(self):\n        print(\"Method 1 implemented\")\n\n    def required_method2(self):\n        print(\"Method 2 implemented\")\n\n# Define the required function\ndef required_function():\n    print(\"Required function implemented\")\n<\/pre>\n<p>\u5728\u6b64\u5916\u90e8\u6a21\u5757\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u53d8\u91cf required_var1 \u548c required_var2\uff0c\u4ee5\u53ca\u7c7b myrequiredclass \u548c\u51fd\u6570 required_function\u3002\u8be5\u7ed3\u6784\u9075\u5faa\u4e3b\u6a21\u5757\u8bbe\u5b9a\u7684\u89c4\u5219\uff0c\u786e\u4fdd\u96c6\u6210\u987a\u5229\u3001\u5408\u89c4\u3002<\/p>\n<p>\u8981\u542f\u7528\u4e3b\u52a8\u9a8c\u8bc1\uff0c\u5916\u90e8\u6a21\u5757\uff08\u5bfc\u5165\u60a8\u7684\u4ee3\u7801\uff09\u5fc5\u987b\u9075\u5faa\u5f00\u53d1\u4eba\u5458\u4f7f\u7528 importspy \u5b9a\u4e49\u7684\u7ed3\u6784\u3002\u9a8c\u8bc1\u8fc7\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li> <strong>\u5b9a\u4e49\u89c4\u5219<\/strong>\uff1a\u5f00\u53d1\u4eba\u5458\u4f7f\u7528 importspy \u5b9a\u4e49\u4e00\u4e2a\u6a21\u578b (spymodel)\uff0c\u6982\u8ff0\u5916\u90e8\u6a21\u5757\u7684\u9884\u671f\u7ed3\u6784\u548c\u884c\u4e3a\u3002<\/li>\n<li> <strong>\u5bfc\u5165\u5916\u90e8\u6a21\u5757<\/strong>\uff1a\u5f53\u5916\u90e8\u6a21\u5757\u5c1d\u8bd5\u5bfc\u5165\u5f00\u53d1\u4eba\u5458\u7684\u4ee3\u7801\u65f6\uff0cimportspy \u4f1a\u68c0\u67e5\u5bfc\u5165\u7684\u6a21\u5757\u662f\u5426\u7b26\u5408\u9884\u5b9a\u4e49\u7684\u89c4\u5219\uff0c\u4f8b\u5982\u662f\u5426\u5b58\u5728\u7279\u5b9a\u53d8\u91cf\u3001\u51fd\u6570\u6216\u7c7b\u3002<\/li>\n<li> <strong>\u9a8c\u8bc1\u7ed3\u679c<\/strong>\uff1a\u5982\u679c\u5bfc\u5165\u7684\u6a21\u5757\u7b26\u5408\u8981\u6c42\uff0c\u5219\u9a8c\u8bc1\u6210\u529f\uff0c\u5bfc\u5165\u987a\u5229\u8fdb\u884c\u3002\u5426\u5219\uff0cimportspy \u4f1a\u5f15\u53d1\u6307\u793a\u4e0d\u5408\u89c4\u7684\u9519\u8bef\uff0c\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u907f\u514d\u8fd0\u884c\u65f6\u95ee\u9898\u5e76\u786e\u4fdd\u4ed6\u4eec\u7684\u4ee3\u7801\u6b63\u786e\u96c6\u6210\u5230\u5916\u90e8\u9879\u76ee\u4e2d\u3002<\/li>\n<\/ol>\n<p><strong>importspy<\/strong> \u662f\u786e\u4fdd\u5916\u90e8\u6a21\u5757\u6b63\u786e\u4f7f\u7528\u60a8\u7684 python \u4ee3\u7801\u7684\u91cd\u8981\u5de5\u5177\uff0c\u7279\u522b\u662f\u5728\u591a\u4e2a\u56e2\u961f\u53ef\u80fd\u5904\u7406\u4e0d\u540c\u6a21\u5757\u7684\u5927\u578b\u9879\u76ee\u6216\u654f\u6377\u5f00\u53d1\u73af\u5883\u4e2d\u3002\u901a\u8fc7\u5b9a\u4e49\u548c\u6267\u884c\u5bfc\u5165\u89c4\u5219\uff0cimportspy \u6709\u52a9\u4e8e\u9632\u6b62\u9519\u8bef\u5e76\u63d0\u9ad8\u8f6f\u4ef6\u8d28\u91cf\uff0c\u786e\u4fdd\u60a8\u7684\u4ee3\u7801\u5b89\u5168\u4e00\u81f4\u5730\u96c6\u6210\u3002<\/p>\n<p>\u5b9e\u65f6\u76d1\u63a7\u5bfc\u5165\u7684\u80fd\u529b\uff0c\u52a0\u4e0a\u4e3b\u52a8\u9a8c\u8bc1\u4f9d\u8d56\u9879\uff0c\u4f7f importspy \u6210\u4e3a\u73b0\u4ee3 python \u5f00\u53d1\u7684\u5b9d\u8d35\u8d44\u4ea7\u3002\u5b9e\u73b0\u8fd9\u4e2a\u5e93\u53ef\u4ee5\u8ba9\u5f00\u53d1\u4eba\u5458\u76f8\u4fe1\u4ed6\u4eec\u7684\u4ee3\u7801\u5c06\u6309\u9884\u671f\u4f7f\u7528\uff0c\u4ece\u800c\u6700\u5927\u9650\u5ea6\u5730\u51cf\u5c11\u9519\u8bef\u548c\u51b2\u7a81\u7684\u98ce\u9669\u3002<\/p>\n<p>\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u548c\u8d44\u6e90\uff0c\u60a8\u53ef\u4ee5\u8bbf\u95ee github \u4e0a\u7684 importspy \u5b58\u50a8\u5e93\u3001pypi \u5305\u9875\u9762\u548c\u5b98\u65b9\u6587\u6863\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a\u5728 Python \u4e2d\u7ba1\u7406\u5bfc\u5165\uff1a\u4f7f\u7528 ImportSpy \u4e3b\u52a8\u9a8c\u8bc1\u7684\u91cd\u8981\u6027\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n<p>      \u7248\u672c\u58f0\u660e \u672c\u6587\u8f6c\u8f7d\u4e8e\uff1adev.to \u5982\u6709\u4fb5\u72af\uff0c\u8bf7\u8054\u7cfb\u5220\u9664<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Python \u4e2d\u7ba1\u7406\u5bfc\u5165\uff1a\u4f7f&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-205137","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205137","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=205137"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/205137\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=205137"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=205137"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=205137"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}