{"id":1091084,"date":"2025-01-08T14:08:16","date_gmt":"2025-01-08T06:08:16","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1091084.html"},"modified":"2025-01-08T14:08:19","modified_gmt":"2025-01-08T06:08:19","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e5%86%99%e8%af%8d%e6%b3%95%e5%88%86%e6%9e%90%e5%99%a8-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1091084.html","title":{"rendered":"\u5982\u4f55\u7528python\u5199\u8bcd\u6cd5\u5206\u6790\u5668"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24203429\/951fe261-e869-47f5-97c3-23abccaeb7c2.webp\" alt=\"\u5982\u4f55\u7528python\u5199\u8bcd\u6cd5\u5206\u6790\u5668\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u7528Python\u5199\u8bcd\u6cd5\u5206\u6790\u5668<\/strong><\/p>\n<\/p>\n<p><p><strong>\u7528Python\u5199\u8bcd\u6cd5\u5206\u6790\u5668\u7684\u6838\u5fc3\u6b65\u9aa4\u6709\uff1a\u5b9a\u4e49\u8bcd\u6cd5\u89c4\u5219\u3001\u7f16\u5199\u8bcd\u6cd5\u5206\u6790\u5668\u7c7b\u3001\u5b9e\u73b0\u72b6\u6001\u673a\u903b\u8f91\u3001\u5904\u7406\u8f93\u5165\u4ee3\u7801\u3002<\/strong> \u5176\u4e2d\uff0c<strong>\u5b9a\u4e49\u8bcd\u6cd5\u89c4\u5219<\/strong>\u662f\u6700\u91cd\u8981\u7684\u4e00\u6b65\uff0c\u56e0\u4e3a\u5b83\u51b3\u5b9a\u4e86\u8bcd\u6cd5\u5206\u6790\u5668\u5982\u4f55\u8bc6\u522b\u548c\u5904\u7406\u4e0d\u540c\u7684\u6807\u8bb0\uff08tokens\uff09\u3002<\/p>\n<\/p>\n<p><p>\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u7528Python\u7f16\u5199\u4e00\u4e2a\u57fa\u672c\u7684\u8bcd\u6cd5\u5206\u6790\u5668\uff0c\u5e76\u9010\u6b65\u8bb2\u89e3\u6bcf\u4e2a\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b9a\u4e49\u8bcd\u6cd5\u89c4\u5219<\/h3>\n<\/p>\n<p><p>\u8bcd\u6cd5\u89c4\u5219\u5b9a\u4e49\u4e86\u7a0b\u5e8f\u5c06\u8bc6\u522b\u7684\u6807\u8bb0\u53ca\u5176\u5bf9\u5e94\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\u3002\u5e38\u89c1\u7684\u6807\u8bb0\u7c7b\u578b\u5305\u62ec\u5173\u952e\u5b57\u3001\u6807\u8bc6\u7b26\u3001\u64cd\u4f5c\u7b26\u3001\u6570\u5b57\u548c\u5206\u9694\u7b26\u7b49\u3002\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Python\u7684<code>re<\/code>\u6a21\u5757\u6765\u5b9a\u4e49\u8fd9\u4e9b\u89c4\u5219\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import re<\/p>\n<h2><strong>\u5b9a\u4e49\u8bcd\u6cd5\u89c4\u5219\uff0c\u6bcf\u4e2a\u89c4\u5219\u5305\u542b\u4e00\u4e2a\u540d\u79f0\u548c\u4e00\u4e2a\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/h2>\n<p>rules = [<\/p>\n<p>    (&#39;KEYWORD&#39;, r&#39;\\b(if|else|while|return|function)\\b&#39;),<\/p>\n<p>    (&#39;IDENTIFIER&#39;, r&#39;\\b[A-Za-z_][A-Za-z0-9_]*\\b&#39;),<\/p>\n<p>    (&#39;NUMBER&#39;, r&#39;\\b\\d+(\\.\\d+)?\\b&#39;),<\/p>\n<p>    (&#39;OPERATOR&#39;, r&#39;[+\\-*\/=&lt;&gt;!&amp;|]&#39;),<\/p>\n<p>    (&#39;SEPARATOR&#39;, r&#39;[(),;{}]&#39;),<\/p>\n<p>    (&#39;WHITESPACE&#39;, r&#39;\\s+&#39;),<\/p>\n<p>    (&#39;UNKNOWN&#39;, r&#39;.&#39;),  # \u672a\u77e5\u5b57\u7b26<\/p>\n<p>]<\/p>\n<h2><strong>\u5408\u5e76\u6240\u6709\u89c4\u5219\u7684\u6b63\u5219\u8868\u8fbe\u5f0f<\/strong><\/h2>\n<p>master_pattern = re.compile(&#39;|&#39;.join(f&#39;(?P&lt;{name}&gt;{pattern})&#39; for name, pattern in rules))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u7f16\u5199\u8bcd\u6cd5\u5206\u6790\u5668\u7c7b<\/h3>\n<\/p>\n<p><p>\u8bcd\u6cd5\u5206\u6790\u5668\u7c7b\u8d1f\u8d23\u8bfb\u53d6\u8f93\u5165\u4ee3\u7801\uff0c\u5e76\u6839\u636e\u5b9a\u4e49\u7684\u89c4\u5219\u5c06\u5176\u5206\u89e3\u4e3a\u6807\u8bb0\u3002\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7c7b\u6765\u5b9e\u73b0\u8fd9\u4e00\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Lexer:<\/p>\n<p>    def __init__(self, rules):<\/p>\n<p>        self.rules = rules<\/p>\n<p>        self.master_pattern = re.compile(&#39;|&#39;.join(f&#39;(?P&lt;{name}&gt;{pattern})&#39; for name, pattern in rules))<\/p>\n<p>    def tokenize(self, code):<\/p>\n<p>        tokens = []<\/p>\n<p>        pos = 0<\/p>\n<p>        while pos &lt; len(code):<\/p>\n<p>            match = self.master_pattern.match(code, pos)<\/p>\n<p>            if match:<\/p>\n<p>                token_type = match.lastgroup<\/p>\n<p>                token_value = match.group(token_type)<\/p>\n<p>                if token_type != &#39;WHITESPACE&#39;:  # \u8df3\u8fc7\u7a7a\u767d\u5b57\u7b26<\/p>\n<p>                    tokens.append((token_type, token_value))<\/p>\n<p>                pos = match.end()<\/p>\n<p>            else:<\/p>\n<p>                r<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>se SyntaxError(f&#39;Illegal character at position {pos}&#39;)<\/p>\n<p>        return tokens<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e09\u3001\u5b9e\u73b0\u72b6\u6001\u673a\u903b\u8f91<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u5904\u7406\u4e0d\u540c\u7684\u6807\u8bb0\uff0c\u6211\u4eec\u9700\u8981\u5b9e\u73b0\u4e00\u4e2a\u72b6\u6001\u673a\u3002\u72b6\u6001\u673a\u5728\u6bcf\u4e2a\u72b6\u6001\u4e0b\u6839\u636e\u8f93\u5165\u5b57\u7b26\u7684\u7c7b\u578b\u51b3\u5b9a\u4e0b\u4e00\u6b65\u7684\u52a8\u4f5c\u3002\u6211\u4eec\u53ef\u4ee5\u5728<code>tokenize<\/code>\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u5bf9\u72b6\u6001\u673a\u7684\u5904\u7406\u903b\u8f91\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Lexer:<\/p>\n<p>    def __init__(self, rules):<\/p>\n<p>        self.rules = rules<\/p>\n<p>        self.master_pattern = re.compile(&#39;|&#39;.join(f&#39;(?P&lt;{name}&gt;{pattern})&#39; for name, pattern in rules))<\/p>\n<p>    def tokenize(self, code):<\/p>\n<p>        tokens = []<\/p>\n<p>        pos = 0<\/p>\n<p>        while pos &lt; len(code):<\/p>\n<p>            match = self.master_pattern.match(code, pos)<\/p>\n<p>            if match:<\/p>\n<p>                token_type = match.lastgroup<\/p>\n<p>                token_value = match.group(token_type)<\/p>\n<p>                if token_type != &#39;WHITESPACE&#39;:  # \u8df3\u8fc7\u7a7a\u767d\u5b57\u7b26<\/p>\n<p>                    tokens.append((token_type, token_value))<\/p>\n<p>                pos = match.end()<\/p>\n<p>            else:<\/p>\n<p>                raise SyntaxError(f&#39;Illegal character at position {pos}&#39;)<\/p>\n<p>        return tokens<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u56db\u3001\u5904\u7406\u8f93\u5165\u4ee3\u7801<\/h3>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6211\u4eec\u9700\u8981\u5904\u7406\u8f93\u5165\u4ee3\u7801\u5e76\u4f7f\u7528\u8bcd\u6cd5\u5206\u6790\u5668\u5c06\u5176\u5206\u89e3\u4e3a\u6807\u8bb0\u3002\u53ef\u4ee5\u7f16\u5199\u4e00\u4e2a\u7b80\u5355\u7684\u51fd\u6570\u6765\u8bfb\u53d6\u8f93\u5165\u4ee3\u7801\uff0c\u5e76\u8c03\u7528\u8bcd\u6cd5\u5206\u6790\u5668\u7684<code>tokenize<\/code>\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def main():<\/p>\n<p>    code = &quot;&quot;&quot;<\/p>\n<p>    function add(a, b) {<\/p>\n<p>        return a + b;<\/p>\n<p>    }<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    lexer = Lexer(rules)<\/p>\n<p>    tokens = lexer.tokenize(code)<\/p>\n<p>    for token in tokens:<\/p>\n<p>        print(token)<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e94\u3001\u8fdb\u9636\u529f\u80fd<\/h3>\n<\/p>\n<p><p>\u5bf9\u4e8e\u66f4\u590d\u6742\u7684\u8bcd\u6cd5\u5206\u6790\u5668\uff0c\u6211\u4eec\u53ef\u4ee5\u6dfb\u52a0\u66f4\u591a\u529f\u80fd\uff0c\u5982\u5904\u7406\u6ce8\u91ca\u3001\u5b57\u7b26\u4e32\u3001\u9519\u8bef\u62a5\u544a\u7b49\u3002\u4e0b\u9762\u662f\u4e00\u4e9b\u8fdb\u9636\u529f\u80fd\u7684\u5b9e\u73b0\u793a\u4f8b\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5904\u7406\u6ce8\u91ca<\/h4>\n<\/p>\n<p><p>\u6211\u4eec\u53ef\u4ee5\u6269\u5c55\u8bcd\u6cd5\u89c4\u5219\uff0c\u6dfb\u52a0\u5bf9\u6ce8\u91ca\u7684\u5904\u7406\u3002\u901a\u5e38\uff0c\u6ce8\u91ca\u5305\u62ec\u5355\u884c\u6ce8\u91ca\u548c\u591a\u884c\u6ce8\u91ca\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">rules = [<\/p>\n<p>    # \u6dfb\u52a0\u6ce8\u91ca\u89c4\u5219<\/p>\n<p>    (&#39;COMMENT&#39;, r&#39;\/\/.*?$|\/\\*.*?\\*\/&#39;),<\/p>\n<p>    # \u5176\u4ed6\u89c4\u5219<\/p>\n<p>    (&#39;KEYWORD&#39;, r&#39;\\b(if|else|while|return|function)\\b&#39;),<\/p>\n<p>    (&#39;IDENTIFIER&#39;, r&#39;\\b[A-Za-z_][A-Za-z0-9_]*\\b&#39;),<\/p>\n<p>    (&#39;NUMBER&#39;, r&#39;\\b\\d+(\\.\\d+)?\\b&#39;),<\/p>\n<p>    (&#39;OPERATOR&#39;, r&#39;[+\\-*\/=&lt;&gt;!&amp;|]&#39;),<\/p>\n<p>    (&#39;SEPARATOR&#39;, r&#39;[(),;{}]&#39;),<\/p>\n<p>    (&#39;WHITESPACE&#39;, r&#39;\\s+&#39;),<\/p>\n<p>    (&#39;UNKNOWN&#39;, r&#39;.&#39;),<\/p>\n<p>]<\/p>\n<h2><strong>\u4fee\u6539tokenize\u65b9\u6cd5\uff0c\u8df3\u8fc7\u6ce8\u91ca<\/strong><\/h2>\n<p>def tokenize(self, code):<\/p>\n<p>    tokens = []<\/p>\n<p>    pos = 0<\/p>\n<p>    while pos &lt; len(code):<\/p>\n<p>        match = self.master_pattern.match(code, pos)<\/p>\n<p>        if match:<\/p>\n<p>            token_type = match.lastgroup<\/p>\n<p>            token_value = match.group(token_type)<\/p>\n<p>            if token_type not in (&#39;WHITESPACE&#39;, &#39;COMMENT&#39;):  # \u8df3\u8fc7\u7a7a\u767d\u5b57\u7b26\u548c\u6ce8\u91ca<\/p>\n<p>                tokens.append((token_type, token_value))<\/p>\n<p>            pos = match.end()<\/p>\n<p>        else:<\/p>\n<p>            raise SyntaxError(f&#39;Illegal character at position {pos}&#39;)<\/p>\n<p>    return tokens<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u5904\u7406\u5b57\u7b26\u4e32<\/h4>\n<\/p>\n<p><p>\u5b57\u7b26\u4e32\u901a\u5e38\u7528\u5f15\u53f7\u62ec\u8d77\u6765\uff0c\u53ef\u4ee5\u662f\u5355\u5f15\u53f7\u6216\u53cc\u5f15\u53f7\u3002\u6211\u4eec\u53ef\u4ee5\u6269\u5c55\u8bcd\u6cd5\u89c4\u5219\uff0c\u6dfb\u52a0\u5bf9\u5b57\u7b26\u4e32\u7684\u5904\u7406\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">rules = [<\/p>\n<p>    # \u6dfb\u52a0\u5b57\u7b26\u4e32\u89c4\u5219<\/p>\n<p>    (&#39;STRING&#39;, r&#39;\\&#39;[^\\&#39;]*\\&#39;|\\&quot;[^\\&quot;]*\\&quot;&#39;),<\/p>\n<p>    # \u5176\u4ed6\u89c4\u5219<\/p>\n<p>    (&#39;KEYWORD&#39;, r&#39;\\b(if|else|while|return|function)\\b&#39;),<\/p>\n<p>    (&#39;IDENTIFIER&#39;, r&#39;\\b[A-Za-z_][A-Za-z0-9_]*\\b&#39;),<\/p>\n<p>    (&#39;NUMBER&#39;, r&#39;\\b\\d+(\\.\\d+)?\\b&#39;),<\/p>\n<p>    (&#39;OPERATOR&#39;, r&#39;[+\\-*\/=&lt;&gt;!&amp;|]&#39;),<\/p>\n<p>    (&#39;SEPARATOR&#39;, r&#39;[(),;{}]&#39;),<\/p>\n<p>    (&#39;WHITESPACE&#39;, r&#39;\\s+&#39;),<\/p>\n<p>    (&#39;UNKNOWN&#39;, r&#39;.&#39;),<\/p>\n<p>]<\/p>\n<h2><strong>\u4fee\u6539tokenize\u65b9\u6cd5\uff0c\u5904\u7406\u5b57\u7b26\u4e32<\/strong><\/h2>\n<p>def tokenize(self, code):<\/p>\n<p>    tokens = []<\/p>\n<p>    pos = 0<\/p>\n<p>    while pos &lt; len(code):<\/p>\n<p>        match = self.master_pattern.match(code, pos)<\/p>\n<p>        if match:<\/p>\n<p>            token_type = match.lastgroup<\/p>\n<p>            token_value = match.group(token_type)<\/p>\n<p>            if token_type not in (&#39;WHITESPACE&#39;, &#39;COMMENT&#39;):  # \u8df3\u8fc7\u7a7a\u767d\u5b57\u7b26\u548c\u6ce8\u91ca<\/p>\n<p>                tokens.append((token_type, token_value))<\/p>\n<p>            pos = match.end()<\/p>\n<p>        else:<\/p>\n<p>            raise SyntaxError(f&#39;Illegal character at position {pos}&#39;)<\/p>\n<p>    return tokens<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u9519\u8bef\u62a5\u544a<\/h4>\n<\/p>\n<p><p>\u5f53\u8bcd\u6cd5\u5206\u6790\u5668\u9047\u5230\u975e\u6cd5\u5b57\u7b26\u65f6\uff0c\u9700\u8981\u62a5\u544a\u9519\u8bef\u4f4d\u7f6e\u3002\u6211\u4eec\u53ef\u4ee5\u5728<code>tokenize<\/code>\u65b9\u6cd5\u4e2d\u6dfb\u52a0\u9519\u8bef\u62a5\u544a\u529f\u80fd\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def tokenize(self, code):<\/p>\n<p>    tokens = []<\/p>\n<p>    pos = 0<\/p>\n<p>    while pos &lt; len(code):<\/p>\n<p>        match = self.master_pattern.match(code, pos)<\/p>\n<p>        if match:<\/p>\n<p>            token_type = match.lastgroup<\/p>\n<p>            token_value = match.group(token_type)<\/p>\n<p>            if token_type not in (&#39;WHITESPACE&#39;, &#39;COMMENT&#39;):  # \u8df3\u8fc7\u7a7a\u767d\u5b57\u7b26\u548c\u6ce8\u91ca<\/p>\n<p>                tokens.append((token_type, token_value))<\/p>\n<p>            pos = match.end()<\/p>\n<p>        else:<\/p>\n<p>            raise SyntaxError(f&#39;Illegal character at position {pos}: {code[pos]}&#39;)<\/p>\n<p>    return tokens<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u4e00\u4e2a\u57fa\u672c\u7684\u8bcd\u6cd5\u5206\u6790\u5668\uff0c\u5e76\u6839\u636e\u9700\u8981\u6dfb\u52a0\u66f4\u591a\u529f\u80fd\u3002\u8bcd\u6cd5\u5206\u6790\u5668\u662f\u7f16\u8bd1\u5668\u548c\u89e3\u91ca\u5668\u7684\u5173\u952e\u7ec4\u4ef6\u4e4b\u4e00\uff0c\u5b83\u5c06\u6e90\u4ee3\u7801\u5206\u89e3\u4e3a\u6807\u8bb0\uff0c\u4e3a\u540e\u7eed\u7684\u8bed\u6cd5\u5206\u6790\u548c\u4ee3\u7801\u751f\u6210\u6253\u4e0b\u57fa\u7840\u3002\u5e0c\u671b\u901a\u8fc7\u672c\u6587\u7684\u4ecb\u7ecd\uff0c\u60a8\u80fd\u66f4\u597d\u5730\u7406\u89e3\u548c\u638c\u63e1\u8bcd\u6cd5\u5206\u6790\u5668\u7684\u5b9e\u73b0\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5f00\u59cb\u521b\u5efa\u4e00\u4e2a\u8bcd\u6cd5\u5206\u6790\u5668\uff1f<\/strong><br \/>\u521b\u5efa\u8bcd\u6cd5\u5206\u6790\u5668\u7684\u7b2c\u4e00\u6b65\u662f\u5b9a\u4e49\u9700\u8981\u5206\u6790\u7684\u8bed\u8a00\u7684\u8bcd\u6cd5\u89c4\u5219\u3002\u53ef\u4ee5\u4ece\u7b80\u5355\u7684\u5173\u952e\u5b57\u3001\u6807\u8bc6\u7b26\u3001\u64cd\u4f5c\u7b26\u548c\u5206\u9694\u7b26\u5f00\u59cb\u3002\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u6765\u5339\u914d\u8fd9\u4e9b\u5143\u7d20\u3002\u53ef\u4ee5\u5229\u7528Python\u7684<code>re<\/code>\u6a21\u5757\u6765\u5b9e\u73b0\u8fd9\u4e00\u70b9\uff0c\u4ee5\u4fbf\u5feb\u901f\u8bc6\u522b\u8f93\u5165\u5b57\u7b26\u4e32\u4e2d\u7684\u5404\u4e2a\u8bcd\u6cd5\u5355\u5143\u3002<\/p>\n<p><strong>\u5728\u5b9e\u73b0\u8bcd\u6cd5\u5206\u6790\u5668\u65f6\uff0c\u5982\u4f55\u5904\u7406\u9519\u8bef\uff1f<\/strong><br \/>\u5728\u8bcd\u6cd5\u5206\u6790\u8fc7\u7a0b\u4e2d\uff0c\u5904\u7406\u9519\u8bef\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u53ef\u4ee5\u901a\u8fc7\u6dfb\u52a0\u9519\u8bef\u5904\u7406\u673a\u5236\u6765\u6355\u83b7\u65e0\u6548\u7684\u8bcd\u6cd5\u5355\u5143\u3002\u4f8b\u5982\uff0c\u5f53\u8f93\u5165\u4e2d\u51fa\u73b0\u4e0d\u7b26\u5408\u9884\u671f\u7684\u5b57\u7b26\u65f6\uff0c\u53ef\u4ee5\u629b\u51fa\u5f02\u5e38\u5e76\u63d0\u4f9b\u8be6\u7ec6\u7684\u9519\u8bef\u4fe1\u606f\u3002\u8fd9\u5c06\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u5e76\u8fdb\u884c\u4fee\u6b63\u3002<\/p>\n<p><strong>\u5982\u4f55\u6d4b\u8bd5\u6211\u7684\u8bcd\u6cd5\u5206\u6790\u5668\u7684\u51c6\u786e\u6027\uff1f<\/strong><br \/>\u53ef\u4ee5\u901a\u8fc7\u7f16\u5199\u4e00\u7cfb\u5217\u6d4b\u8bd5\u7528\u4f8b\u6765\u9a8c\u8bc1\u8bcd\u6cd5\u5206\u6790\u5668\u7684\u51c6\u786e\u6027\u3002\u8fd9\u4e9b\u6d4b\u8bd5\u7528\u4f8b\u5e94\u5305\u542b\u4e0d\u540c\u7684\u8f93\u5165\u5b57\u7b26\u4e32\uff0c\u6db5\u76d6\u6240\u6709\u53ef\u80fd\u7684\u8fb9\u754c\u60c5\u51b5\uff0c\u5305\u62ec\u6709\u6548\u7684\u548c\u65e0\u6548\u7684\u8bcd\u6cd5\u5355\u5143\u3002\u4f7f\u7528Python\u7684\u5355\u5143\u6d4b\u8bd5\u6846\u67b6\uff0c\u5982<code>unittest<\/code>\uff0c\u53ef\u4ee5\u5e2e\u52a9\u81ea\u52a8\u5316\u6d4b\u8bd5\u8fc7\u7a0b\uff0c\u5e76\u786e\u4fdd\u5728\u4fee\u6539\u4ee3\u7801\u65f6\u4fdd\u6301\u529f\u80fd\u7684\u5b8c\u6574\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u7528Python\u5199\u8bcd\u6cd5\u5206\u6790\u5668 \u7528Python\u5199\u8bcd\u6cd5\u5206\u6790\u5668\u7684\u6838\u5fc3\u6b65\u9aa4\u6709\uff1a\u5b9a\u4e49\u8bcd\u6cd5\u89c4\u5219\u3001\u7f16\u5199\u8bcd\u6cd5\u5206\u6790\u5668\u7c7b\u3001\u5b9e\u73b0\u72b6 [&hellip;]","protected":false},"author":3,"featured_media":1091092,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1091084"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1091084"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1091084\/revisions"}],"predecessor-version":[{"id":1091095,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1091084\/revisions\/1091095"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1091092"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1091084"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1091084"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1091084"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}