{"id":2004,"date":"2019-01-02T03:07:50","date_gmt":"2019-01-02T03:07:50","guid":{"rendered":""},"modified":"2019-01-02T11:08:14","modified_gmt":"2019-01-02T03:08:14","slug":"python%e5%ae%98%e6%96%b9%e7%ab%9f%e7%84%b6%e7%bb%99%e5%87%ba%e4%ba%86%e4%b8%80%e7%a7%8d%e7%bc%96%e7%a0%81%e8%a7%84%e8%8c%83pep+8","status":"publish","type":"post","link":"http:\/\/www.szryc.com\/?p=2004","title":{"rendered":"Python\u5b98\u65b9\u7adf\u7136\u7ed9\u51fa\u4e86\u4e00\u79cd\u7f16\u7801\u89c4\u8303PEP 8"},"content":{"rendered":"

\n\t\u5199\u5728\u4e4b\u524d<\/p>\n

\n\t\u6bcf\u4e2a\u4eba\u90fd\u6709\u81ea\u5df1\u7684\u4ee3\u7801\u98ce\u683c\uff0c\u968f\u7740\u5199\u7684\u884c\u6570\u589e\u52a0\uff0c\u81ea\u5df1\u5bf9\u4e8e\u4ee3\u7801\u7684\u5ba1\u7f8e\u4e5f\u4f1a\u53d8\u7684\u4e0d\u4e00\u6837\uff0c\u8fd9\u5c31\u50cf\u662f\u4e00\u4e2a\u9010\u6e10\u8715\u53d8\u7684\u8fc7\u7a0b\uff0c\u6bcf\u8fc7\u4e00\u6bb5\u65f6\u95f4\u56de\u5934\u518d\u53bb\u770b\u770b\u81ea\u5df1\u4e4b\u524d\u5199\u7684\u4ee3\u7801\u5c31\u4f1a\u751f\u51fa\u4e00\u79cd\u300c\u8fd9\u4e48\u4e11\u7684\u73a9\u610f\u513f\u7adf\u7136\u662f\u6211\u5199\u7684\u300d\u8fd9\u79cd\u611f\u6168\u3002<\/p>\n

\n\t <\/div>\n

\n\t\u4e4b\u524d\u4e0d\u8bba\u662f\u5199 C \u6216\u8005\u662f C++<\/u> \u7684\u65f6\u5019\uff0c\u5bf9\u4e8e\u4ee3\u7801\u98ce\u683c\u7684\u597d\u574f\u89c2\u611f\u5b8c\u5168\u662f\u51ed\u7740\u81ea\u5df1\u7684\u4e3b\u89c2\u610f\u8bc6\uff0c\u4e5f\u6ca1\u6709\u4ec0\u4e48\u5b98\u65b9\u6807\u51c6\u8bf4\u8fd9\u6837\u90a3\u6837\u5c31\u662f\u597d\u770b\u7684\u3002\u7b49\u5b66\u4e86 Python<\/u> \u4ee5\u540e\uff0c\u795e\u5947\u7684\u53d1\u73b0 Python \u5b98\u65b9\u7adf\u7136\u7ed9\u51fa\u4e86\u4e00\u79cd\u7f16\u7801\u89c4\u8303 PEP 8\uff0c\u5f53\u7136\u8fd9\u4e2a\u53ea\u662f\u4e2a\u6807\u51c6\u800c\u5df2\uff0c\u5e76\u6ca1\u6709\u5f3a\u5236\u8981\u6c42\u5927\u5bb6\u90fd\u8981\u53bb\u9075\u5b88\uff0c\u4f46\u53c8\u597d\u50cf\u5927\u591a\u6570\u4eba\u90fd\u4f7f\u7528\u4e86 PEP 8 \u7f16\u7801\u98ce\u683c\uff0c\u4f7f\u5b83\u5df2\u7ecf\u6210\u4e3a\u4e86\u4e8b\u5b9e\u4e0a\u7684\u4ee3\u7801\u98ce\u683c\u6807\u51c6\u3002<\/p>\n

\n\tPEP 8 \u7f16\u7801\u89c4\u8303<\/p>\n

\n\tPython \u4ee3\u7801\u4ece\u7b2c\u4e00\u773c\u770b\u4e0a\u53bb\uff0c\u7ed9\u4eba\u7684\u611f\u89c9\u5c31\u662f\u7b80\u6d01\u4f18\u7f8e\uff0c\u53ef\u8bfb\u6027\u5f3a\uff0c\u4e5f\u5c31\u662f\u6211\u4eec\u65e5\u5e38\u6240\u8bf4\u7684\u300c\u9ad8\u989c\u503c\u300d\u3002\u4e00\u65b9\u9762\u662f\u56e0\u4e3a Python \u81ea\u8eab\u7684\u4f18\u79c0\u8bbe\u8ba1\uff0c\u6bd4\u5982\u7edf\u4e00\u7684\u9501\u8fdb\uff0c\u6ca1\u6709\u591a\u4f59\u7684\u7b26\u53f7\u4ece\u800c\u8ba9\u4ee3\u7801\u53d8\u7684\u66f4\u52a0\u7b80\u6d01\uff1b\u53e6\u4e00\u65b9\u9762\u5c31\u662f\u56e0\u4e3a\u5b83\u6709\u7740\u4e00\u5957\u8f83\u4e3a\u7edf\u4e00\u7684\u7f16\u7801\u98ce\u683c\uff0c\u5f53\u7136\u5b83\u672c\u8eab\u53ea\u662f\u7f16\u7801\u98ce\u683c\u65b9\u9762\u7684\u5efa\u8bae\u800c\u4e0d\u662f\u5f3a\u5236\uff0c\u76f8\u5e94\u7684\u5728\u7f16\u5199 Python \u4ee3\u7801\u7684\u7f16\u8f91\u5668\u81ea\u52a8\u63d0\u4f9b PFP 8 \u68c0\u67e5\uff0c\u5f53\u4f60\u7f16\u5199\u7684\u4ee3\u7801\u8fdd\u53cd\u4e86 PEP 8 \u89c4\u8303\u7684\u65f6\u5019\uff0c\u4f1a\u7ed9\u51fa\u8b66\u544a\u4fe1\u606f\u548c\u4fee\u6b63\u7684\u5efa\u8bae\u3002\u4e0e\u6b64\u540c\u65f6\uff0c\u8fd8\u6709\u4e13\u95e8\u7684\u68c0\u67e5\u5de5\u5177\u5bf9 Python \u7684\u4ee3\u7801\u98ce\u683c\u8fdb\u884c\u68c0\u67e5\u3002<\/p>\n

\n\t\u7531\u4e0a\uff0c\u8fd8\u662f\u5efa\u8bae\u5728\u7f16\u5199 Python \u4ee3\u7801\u7684\u65f6\u5019\u90fd\u9075\u5faa PEP 8 \u7f16\u7801\u89c4\u8303\uff0c\u6bd5\u7adf\u4f60\u4ee5\u540e\u4e0d\u53ef\u80fd\u662f\u53ea\u4e00\u4e2a\u4eba\u5199\u4ee3\u7801\uff0c\u672a\u6765\u4e0d\u8bba\u662f\u5728\u516c\u53f8\u6216\u8005\u67d0\u4e9b\u5f00\u6e90\u9879\u76ee\u4e2d\uff0c\u4f5c\u4e3a\u5176\u4e2d\u7684\u4e00\u4efd\u5b50\uff0c\u80af\u5b9a\u8fd8\u662f\u8981\u5728\u98ce\u683c\u4e0a\u5411\u5927\u4f17\u770b\u9f50\u7684\u3002<\/p>\n

\n\tPEP 8 \u7f16\u7801\u89c4\u8303\u8be6\u7ec6\u7684\u7ed9\u51fa\u4e86 Python \u7f16\u7801\u7684\u6307\u5bfc\uff0c\u5305\u62ec\u4ec0\u4e48\u5bf9\u9f50\u5566\uff0c\u5305\u7684\u5bfc\u5165\u987a\u5e8f\u5566\uff0c\u7a7a\u683c\u548c\u6ce8\u91ca\u5566\u8fd8\u6709\u547d\u540d\u4e60\u60ef\u7b49\u65b9\u65b9\u9762\u9762\uff0c\u5e76\u4e14\u8fd8\u6709\u8be6\u7ec6\u7684\u4e8b\u4f8b\u3002<\/p>\n

\n\t\u4e0b\u9762\u6211\u4ee5\u300c\u5305\u300d\u7684\u5bfc\u5165\u4e3a\u4f8b\uff0c\u770b\u4e00\u4e0b PEP 8 \u7ed9\u51fa\u7684\u5177\u4f53\u7f16\u7a0b\u6307\u5bfc\u3002\u5728 Python \u4e2d\uff0c import \u5e94\u8be5\u4e00\u6b21\u53ea\u5bfc\u5165\u4e00\u4e2a\u6a21\u5757\uff0c\u4e0d\u540c\u7684\u6a21\u5757\u5e94\u8be5\u72ec\u7acb\u4e00\u884c\uff1a<\/p>\n

\n\timport pandasimport numpy<\/p>\n

\n\t\u53cd\u9762\u4f8b\u5b50\uff1a<\/p>\n

\n\timport pandas,numpy<\/p>\n

\n\t\u5982\u679c\u60f3\u8981\u4ece\u4e00\u4e2a\u6a21\u5757\u91cc\u9762\u5bfc\u5165\u591a\u4e2a\uff0c\u4e5f\u53ef\u4ee5\u50cf\u4e0b\u9762\u8fd9\u6837\uff1a<\/p>\n

\n\tfrom<\/u> subprocess import Popen, PI<\/u>PE<\/p>\n

\n\timport \u8bed\u53e5\u5e94\u8be5\u5904\u4e8e\u6e90\u7801\u6587\u4ef6\u7684\u9876\u90e8\uff0c\u4f4d\u4e8e\u6a21\u5757\u6ce8\u91ca\u548c\u6587\u6863\u5b57\u7b26\u4e32\u4e4b\u540e\uff0c\u5168\u5c40\u53d8\u91cf\u548c\u5e38\u91cf\u4e4b\u524d\u3002\u5728\u5bfc\u5165\u4e0d\u540c\u7684\u5e93\u7684\u65f6\u5019\uff0c\u5e94\u8be5\u6309\u7167\u4ee5\u4e0b\u7684\u987a\u5e8f\u5206\u7ec4\uff0c\u5404\u4e2a\u5206\u7ec4\u4e4b\u95f4\u4ee5\u7a7a\u884c\u5206\u9694\uff1a<\/p>\n

\n\t\u5bfc\u5165\u6807\u51c6\u5e93\u6a21\u5757<\/p>\n

\n\t\u5bfc\u5165\u76f8\u5173\u7b2c\u4e09\u65b9\u5e93\u6a21\u5757<\/p>\n

\n\t\u5bfc\u5165\u5f53\u524d\u5e94\u7528\u7a0b\u5e8f\/\u5e93\u6a21\u5757<\/p>\n

\n\t\u5177\u4f53\u4e8b\u4f8b\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\n\timport osimport ti<\/u>meimport psutilfrom te<\/u>st import u_test,my_test<\/p>\n

\n\tPython \u4e2d\u8fd8\u652f\u6301\u76f8\u5bf9\u5bfc\u5165\u548c\u7edd\u5bf9\u5bfc\u5165\uff0c\u5728\u8fd9\u91cc\u8fd8\u662f\u5f3a\u63a8\u7edd\u5bf9\u5bfc\u5165\u3002\u56e0\u4e3a\u7edd\u5bf9\u5bfc\u5165\u7684\u53ef\u8bfb\u6027\u66f4\u597d\u4e00\u4e9b\uff0c\u4e5f\u4e0d\u5bb9\u6613\u51fa\u9519\uff0c\u5373\u4f7f\u51fa\u9519\u4e86\u4e5f\u4f1a\u7ed9\u51fa\u66f4\u52a0\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u3002\u5177\u4f53\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\n\tfrom sub_package import toolsfrom sub_package.tools  import msg<\/p>\n

\n\t\u5f53\u7136\u9664\u4e86\u4e0a\u8ff0\u4ee5\u5916\u8fd8\u6709\u66f4\u591a\u5bf9\u4e8e\u5305\u7684\u89c4\u8303\u7684\u63cf\u8ff0\uff0cPEP 8 \u7684\u7f16\u7801\u98ce\u683c\u6307\u5bfc\u6bd4\u8f83\u957f\uff0c\u5e76\u4e14\u5199\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u6240\u4ee5\u6211\u5c31\u4e0d\u5728\u8fd9\u4e00\u4e00\u4ecb\u7ecd\u4e86\uff0c\u8be6\u7ec6\u7684\u53ef\u4ee5\u53c2\u8003 Python \u5b98\u7f51\u4e0a\u7684\u8d44\u6599\u3002<\/p>\n

\n\tpycodestyle \u68c0\u67e5\u4ee3\u7801\u89c4\u8303<\/p>\n

\n\t\u6211\u5728\u4e0a\u9762\u8bf4\u8fc7 PEP 8 \u53ea\u662f\u5b98\u65b9\u7ed9\u51fa\u7684 Python \u7f16\u7801\u89c4\u8303\uff0c\u5e76\u6ca1\u6709\u5f3a\u5236\u8981\u6c42\u5927\u5bb6\u90fd\u9075\u5b88\uff0c\u4f46\u662f\u53c8\u7531\u4e8e\u5927\u5bb6\u90fd\u5728\u7528\uff0c\u6240\u4ee5\u5b83\u4e5f\u5c31\u53d8\u6210\u4e86\u4e8b\u5b9e\u4e0a\u7684 Python \u4ee3\u7801\u98ce\u683c\u6807\u51c6\uff0c\u65e2\u7136\u90fd\u662f\u6807\u51c6\u4e86\uff0c\u90a3\u4e48\u5c31\u5e94\u8be5\u6709\u5de5\u5177\u6765\u68c0\u67e5\u8fd9\u4e2a\u6807\u51c6\uff0c\u8fd9\u6837\u53ef\u4ee5\u5e2e\u52a9 Python \u5c0f\u767d\u89c4\u8303\u81ea\u5df1\u7684\u4ee3\u7801\uff0c\u4e5f\u53ef\u4ee5\u5e2e\u52a9\u5927\u5bb6\u5728\u5f00\u6e90\u6216\u8005\u5de5\u4f5c\u4e2d\u5f62\u6210\u7edf\u4e00\u7684\u4ee3\u7801\u98ce\u683c\u3002<\/p>\n

\n\t\u4e3a\u4e86\u8fbe\u6210\u4e0a\u8ff0\u7684\u76ee\u7684\uff0c\u5b98\u65b9\u63d0\u4f9b\u4e86\u540c\u540d\u7684\u547d\u4ee4\u884c\u5de5\u5177\u6765\u68c0\u67e5 Python \u4ee3\u7801\u662f\u5426\u8fdd\u53cd\u4e86 PEP 8 \u89c4\u8303\uff0c\u5e76\u4e14\u5bf9\u8fdd\u53cd\u89c4\u8303\u7684\u5730\u65b9\u7ed9\u51fa\u4e86\u76f8\u5e94\u7684\u63d0\u793a\u4fe1\u606f\u3002<\/p>\n

\n\tpip install pep8<\/p>\n

\n\t\u89c4\u8303\u7684\u540d\u5b57\u662f PEP 8 \uff0c\u8fd9\u4e2a\u68c0\u67e5\u4ee3\u7801\u98ce\u683c\u7684\u547d\u4ee4\u884c\u5de5\u5177\u53eb pep8\uff0c\u8fd9\u4e2a\u5f88\u5bb9\u6613\u5f15\u8d77\u5927\u5bb6\u7684\u56f0\u60d1\uff0c\u56e0\u6b64 Python \u4e4b\u7236\u5efa\u8bae\u5c06 pep8 \u91cd\u65b0\u547d\u540d\u4e3a pycodestyle\uff0c\u4e0b\u9762\u6211\u4eec\u6765\u770b\u4e00\u4e0b pycodestyle \u7684\u7528\u6cd5\u3002<\/p>\n

\n\t\u9996\u5148\u901a\u8fc7 pip \u5b89\u88c5\u4e00\u4e0b\uff1a<\/p>\n

\n\tpip install pycodestyle<\/p>\n

\n\t\u5bf9\u4e00\u4e2a\u6216\u8005\u591a\u4e2a\u6587\u4ef6\u8fd0\u884c pycodestyle\uff0c\u6253\u5370\u68c0\u67e5\u62a5\u544a\uff1a<\/p>\n

\n\t<\/p>\n

\n\t\u901a\u8fc7 --show-source \u663e\u793a\u4e0d\u7b26\u5408\u89c4\u8303\u7684\u6e90\u7801\uff0c\u4ee5\u4fbf\u7a0b\u5e8f\u5458\u8fdb\u884c\u4fee\u6539\uff0c\u5177\u4f53\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\n\t<\/p>\n

\n\tautopep8 \u683c\u5f0f\u5316\u4ee3\u7801<\/p>\n

\n\tautopep8 \u80fd\u591f\u5c06 Python \u4ee3\u7801\u81ea\u52a8\u683c\u5f0f\u5316\u4e3a PEP 8 \u98ce\u683c\uff0c\u5b83\u4f7f\u7528 pycodestyle \u5de5\u5177\u6765\u51b3\u5b9a\u4ee3\u7801\u4e2d\u7684\u54ea\u90e8\u5206\u9700\u8981\u88ab\u683c\u5f0f\u5316\uff0c\u8fd9\u80fd\u591f\u4fee\u590d\u5927\u90e8\u5206 pycodestyle \u5de5\u5177\u4e2d\u62a5\u544a\u7684\u6392\u7248\u95ee\u9898\u3002autopep8 \u672c\u8eab\u4e5f\u662f\u4e00\u4e2a\u7528 Python \u5199\u7684\u5de5\u5177\uff0c\u6240\u4ee5\u6211\u4eec\u8fd8\u662f\u53ef\u4ee5\u7528 pip \u76f4\u63a5\u5b89\u88c5\uff1a<\/p>\n

\n\tpip install autopep8<\/p>\n

\n\t\u5b83\u7684\u4f7f\u7528\u65b9\u5f0f\u4e5f\u5f88\u7b80\u5355\uff0c\u5177\u4f53\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\n\tautopep8 --in-place test_search.py<\/p>\n

\n\t\u4e0a\u8ff0\u4ee3\u7801\u5982\u679c\u4e0d\u5e26 --in-place \u7684\u8bdd\uff0c\u4f1a\u5c06 autopep8 \u683c\u5f0f\u5316\u4ee5\u540e\u7684\u4ee3\u7801\u76f4\u63a5\u8f93\u51fa\u5230\u63a7\u5236\u53f0\u3002\u6211\u4eec\u53ef\u4ee5\u7528\u8fd9\u79cd\u65b9\u5f0f\u68c0\u67e5 autopep8 \u7684\u4fee\u6539\uff0c\u4f7f\u7528 --in-place \u5219\u4f1a\u76f4\u63a5\u5c06\u7ed3\u679c\u4fdd\u5b58\u5230\u6e90\u6587\u4ef6\u4e2d\u3002\u5728\u8fd9\u6211\u7ee7\u7eed\u7528\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\u7528\u5230\u7684 py \u6587\u4ef6\uff0c\u5177\u4f53\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n

\n\t<\/p>\n

\n\t\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0cautopep8 \u987a\u5229\u7684\u4fee\u590d\u4e86\u6240\u6709\u7684\u95ee\u9898\uff0c\u4f46\u662f\u5982\u679c\u4f60\u8fd9\u4e2a\u65f6\u5019\u67e5\u770b\u6e90\u6587\u4ef6\u7684\u8bdd\uff0c\u4f60\u4f1a\u53d1\u73b0\u6e90\u6587\u4ef6\u7684\u5185\u5bb9\u8fd8\u662f\u548c\u539f\u6765\u4e00\u6837\uff0c\u5e76\u6ca1\u6709\u88ab\u4fee\u6539\u3002\u8fd9\u4e2a\u65f6\u5019\u6211\u4eec\u5c31\u8981\u7528\u5230 --in-place\uff0c\u52a0\u4e0a\u8fd9\u4e2a\u9009\u9879\u5c06\u4e0d\u4f1a\u6709\u4efb\u4f55\u8f93\u51fa\uff0c autopep8 \u4f1a\u76f4\u63a5\u4fee\u6539\u6e90\u6587\u4ef6\u3002<\/p>\n

\n\tautopep8 --in-place test_search.py<\/p>\n","protected":false},"excerpt":{"rendered":"

\u5199\u5728\u4e4b\u524d \u6bcf\u4e2a\u4eba\u90fd\u6709\u81ea\u5df1\u7684\u4ee3\u7801\u98ce\u683c\uff0c\u968f\u7740\u5199\u7684\u884c\u6570\u589e\u52a0\uff0c\u81ea\u5df1\u5bf9\u4e8e\u4ee3\u7801\u7684\u5ba1\u7f8e\u4e5f\u4f1a\u53d8\u7684\u4e0d\u4e00\u6837\uff0c\u8fd9\u5c31\u50cf\u662f\u4e00\u4e2a\u9010\u6e10\u8715\u53d8\u7684\u8fc7\u7a0b\uff0c\u6bcf\u8fc7\u4e00\u6bb5\u65f6\u95f4\u56de\u5934\u518d\u53bb\u770b\u770b\u81ea\u5df1\u4e4b\u524d\u5199\u7684\u4ee3\u7801\u5c31\u4f1a\u751f\u51fa<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"_links":{"self":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/2004"}],"collection":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2004"}],"version-history":[{"count":0,"href":"http:\/\/www.szryc.com\/index.php?rest_route=\/wp\/v2\/posts\/2004\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2004"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.szryc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}