{"id":82950,"date":"2026-07-25T15:08:36","date_gmt":"2026-07-25T07:08:36","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/82950.html"},"modified":"2026-07-25T15:08:36","modified_gmt":"2026-07-25T07:08:36","slug":"python%e8%bf%9b%e9%98%b6%e5%bf%85%e6%9d%80%e6%8a%80-%e9%97%ad%e5%8c%85%e4%b8%89%e8%a6%81%e7%b4%a0%e4%b8%8e%e8%a3%85%e9%a5%b0%e5%99%a8%e5%ae%8c%e5%85%a8%e6%8c%87%e5%8d%97","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/82950.html","title":{"rendered":"Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357"},"content":{"rendered":"<h3>\u524d\u8a00<\/h3>\n<p>\u5982\u679c\u4f60\u5df2\u7ecf\u719f\u6089\u4e86\u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5&#xff0c;\u90a3\u4e48\u606d\u559c\u4f60\u6765\u5230Python\u8fdb\u9636\u7684\u5927\u95e8&#xff01;\u95ed\u5305&#xff08;Closure&#xff09;\u548c\u88c5\u9970\u5668&#xff08;Decorator&#xff09;\u662fPython\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u7cbe\u9ad3&#xff0c;\u4e5f\u662f\u9762\u8bd5\u4e2d\u7ed5\u4e0d\u5f00\u7684\u9ad8\u9891\u8003\u70b9\u3002\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790\u95ed\u5305\u7684\u201c\u4e09\u8981\u7d20\u201d&#xff0c;\u5e76\u5e26\u4f60\u624b\u5199\u901a\u7528\u7684\u65e5\u5fd7\u88c5\u9970\u5668\u3001\u8ba1\u65f6\u88c5\u9970\u5668&#xff0c;\u8ba9\u4f60\u771f\u6b63\u7406\u89e3&#064;\u8bed\u6cd5\u7cd6\u80cc\u540e\u7684\u539f\u7406\u3002<\/p>\n<hr \/>\n<h3>1. \u95ed\u5305&#xff08;Closure&#xff09;\u2014\u2014 \u51fd\u6570\u5de5\u5382\u7684\u57fa\u77f3<\/h3>\n<h4>1.1 \u4ec0\u4e48\u662f\u95ed\u5305&#xff1f;<\/h4>\n<p>\u95ed\u5305\u672c\u8d28\u4e0a\u662f\u4e00\u4e2a\u5d4c\u5957\u51fd\u6570&#xff0c;\u5b83\u8ba9\u5185\u5c42\u51fd\u6570\u6355\u83b7\u5e76\u8bb0\u4f4f\u4e86\u5916\u5c42\u51fd\u6570\u7684\u5c40\u90e8\u53d8\u91cf&#xff0c;\u5373\u4f7f\u5916\u5c42\u51fd\u6570\u5df2\u7ecf\u6267\u884c\u5b8c\u6bd5\u3002<\/p>\n<h4>1.2 \u95ed\u5305\u4e09\u8981\u7d20&#xff08;\u9762\u8bd5\u5fc5\u80cc&#xff09;<\/h4>\n<li>\n<p>\u51fd\u6570\u5d4c\u5957&#xff1a;\u5185\u5c42\u51fd\u6570\u5b9a\u4e49\u5728\u5916\u5c42\u51fd\u6570\u5185\u90e8\u3002<\/p>\n<\/li>\n<li>\n<p>\u5185\u5c42\u51fd\u6570\u4f7f\u7528\u5916\u5c42\u51fd\u6570\u7684\u53d8\u91cf&#xff08;\u6355\u83b7\u72b6\u6001&#xff09;\u3002<\/p>\n<\/li>\n<li>\n<p>\u5916\u5c42\u51fd\u6570\u8fd4\u56de\u5185\u5c42\u51fd\u6570&#xff08;\u628a\u201c\u884c\u4e3a\u201d\u8fd4\u56de\u51fa\u53bb&#xff09;\u3002<\/p>\n<\/li>\n<h4>1.3 \u7ecf\u5178\u6848\u4f8b&#xff1a;\u8ba1\u6570\u5668\u5de5\u5382<\/h4>\n<p>def counter(step):<br \/>\n    count &#061; 0  # \u5916\u90e8\u5c40\u90e8\u53d8\u91cf<br \/>\n    def inner():<br \/>\n        nonlocal count  # \u58f0\u660e\u4fee\u6539\u5916\u90e8\u53d8\u91cf<br \/>\n        count &#043;&#061; step<br \/>\n        return count<br \/>\n    return inner<\/p>\n<p># \u521b\u5efa\u4e24\u4e2a\u72ec\u7acb\u7684\u8ba1\u6570\u5668\u5b9e\u4f8b<br \/>\nc1 &#061; counter(1)<br \/>\nc2 &#061; counter(2)<\/p>\n<p>print(c1())  # 1<br \/>\nprint(c1())  # 2<br \/>\nprint(c2())  # 2<br \/>\nprint(c2())  # 4<\/p>\n<p>\u6bcf\u6b21\u8c03\u7528counter&#xff0c;\u90fd\u4f1a\u751f\u6210\u4e00\u4e2a\u65b0\u7684\u95ed\u5305\u7a7a\u95f4&#xff0c;c1\u548cc2\u7684count\u4e92\u4e0d\u5e72\u6270\u3002<\/p>\n<hr \/>\n<h3>2. \u88c5\u9970\u5668&#xff08;Decorator&#xff09;\u2014\u2014 \u4e0d\u4fee\u6539\u4ee3\u7801&#xff0c;\u53ea\u589e\u5f3a\u529f\u80fd<\/h3>\n<h4>2.1 \u88c5\u9970\u5668\u7684\u672c\u8d28<\/h4>\n<p>\u88c5\u9970\u5668\u5c31\u662f\u4e00\u4e2a\u95ed\u5305&#xff0c;\u5b83\u63a5\u6536\u4e00\u4e2a\u51fd\u6570\u4f5c\u4e3a\u53c2\u6570&#xff0c;\u8fd4\u56de\u4e00\u4e2a\u589e\u5f3a\u540e\u7684\u65b0\u51fd\u6570\u3002<br \/>\n\u8bed\u6cd5\u7cd6\u00a0&#064;deco\u00a0\u7b49\u4ef7\u4e8e\u00a0func &#061; deco(func)\u3002<\/p>\n<h4>2.2 \u7b2c\u4e00\u4e2a\u8ba1\u65f6\u88c5\u9970\u5668<\/h4>\n<p>\u5728\u4e0d\u6539\u52a8\u539f\u51fd\u6570\u7684\u60c5\u51b5\u4e0b&#xff0c;\u8ba1\u7b97\u51fd\u6570\u6267\u884c\u65f6\u95f4&#xff1a;<\/p>\n<p>import time<\/p>\n<p>def timer(func):<br \/>\n    def wrapper():<br \/>\n        start &#061; time.time()<br \/>\n        func()<br \/>\n        print(f&#034;\u51fd\u6570 {func.__name__} \u8017\u65f6: {time.time() &#8211; start:.4f}s&#034;)<br \/>\n    return wrapper<\/p>\n<p>&#064;timer<br \/>\ndef sleep_func():<br \/>\n    time.sleep(1)<\/p>\n<p>sleep_func()  # \u51fd\u6570 sleep_func \u8017\u65f6: 1.0002s<\/p>\n<h4>2.3 \u901a\u7528\u88c5\u9970\u5668&#xff08;\u652f\u6301\u53c2\u6570\u548c\u8fd4\u56de\u503c&#xff09;<\/h4>\n<p>\u5b9e\u9645\u5f00\u53d1\u4e2d&#xff0c;\u539f\u51fd\u6570\u5f80\u5f80\u6709\u53c2\u6570\u548c\u8fd4\u56de\u503c\u3002\u6211\u4eec\u9700\u8981\u7528\u00a0*args, **kwargs\u00a0\u901a\u5403\u4e00\u5207\u3002<\/p>\n<p>def universal_deco(func):<br \/>\n    def wrapper(*args, **kwargs):<br \/>\n        print(f&#034;\u6b63\u5728\u6267\u884c {func.__name__}&#034;)<br \/>\n        result &#061; func(*args, **kwargs)  # \u63a5\u6536\u8fd4\u56de\u503c<br \/>\n        print(&#034;\u6267\u884c\u7ed3\u675f&#034;)<br \/>\n        return result                   # \u8fd4\u56de\u8fd4\u56de\u503c<br \/>\n    return wrapper<\/p>\n<p>&#064;universal_deco<br \/>\ndef add(a, b):<br \/>\n    return a &#043; b<\/p>\n<p>print(add(5, 3))  # 8 (\u540c\u65f6\u6253\u5370\u4e86\u65e5\u5fd7)<\/p>\n<hr \/>\n<h3>3. \u591a\u4e2a\u88c5\u9970\u5668\u53e0\u52a0&#xff08;\u6267\u884c\u987a\u5e8f&#xff09;<\/h3>\n<p>\u5f53\u591a\u4e2a\u88c5\u9970\u5668\u53e0\u5728\u4e00\u8d77\u65f6&#xff0c;\u4ece\u4e0b\u5f80\u4e0a\u5305\u88c5&#xff0c;\u8c03\u7528\u65f6\u4ece\u4e0a\u5f80\u4e0b\u6267\u884c\u3002<\/p>\n<p>def deco1(func):<br \/>\n    def wrapper():<br \/>\n        print(&#034;\u5f00\u59cb\u88c5\u99701&#034;)<br \/>\n        func()<br \/>\n        print(&#034;\u7ed3\u675f\u88c5\u99701&#034;)<br \/>\n    return wrapper<\/p>\n<p>def deco2(func):<br \/>\n    def wrapper():<br \/>\n        print(&#034;\u5f00\u59cb\u88c5\u99702&#034;)<br \/>\n        func()<br \/>\n        print(&#034;\u7ed3\u675f\u88c5\u99702&#034;)<br \/>\n    return wrapper<\/p>\n<p>&#064;deco1<br \/>\n&#064;deco2<br \/>\ndef core():<br \/>\n    print(&#034;\u6838\u5fc3\u4e1a\u52a1&#034;)<\/p>\n<p>core()<br \/>\n# \u8f93\u51fa\u987a\u5e8f&#xff1a;<br \/>\n# \u5f00\u59cb\u88c5\u99701<br \/>\n# \u5f00\u59cb\u88c5\u99702<br \/>\n# \u6838\u5fc3\u4e1a\u52a1<br \/>\n# \u7ed3\u675f\u88c5\u99702<br \/>\n# \u7ed3\u675f\u88c5\u99701<\/p>\n<hr \/>\n<h3>4. \u5b9e\u6218\u6848\u4f8b&#xff08;\u4e00&#xff09;&#xff1a;\u6392\u5e8f\u7b97\u6cd5\u65f6\u95f4\u5f00\u9500\u7edf\u8ba1<\/h3>\n<p>\u6211\u4eec\u751f\u621010000\u4e2a\u968f\u673a\u6570&#xff0c;\u5bf9\u6bd4\u00a0sorted()\u3001list.sort()\u3001\u5192\u6ce1\u6392\u5e8f\u3001\u9009\u62e9\u6392\u5e8f\u7684\u6548\u7387\u3002\u5229\u7528\u88c5\u9970\u5668&#xff0c;\u96f6\u4fb5\u5165\u5730\u7edf\u8ba1\u6bcf\u4e2a\u7b97\u6cd5\u8017\u65f6\u3002<\/p>\n<p>import random<br \/>\nimport time<\/p>\n<p># \u51c6\u59074\u4efd\u76f8\u540c\u7684\u6570\u636e<br \/>\ndata &#061; [random.randint(1, 100000) for _ in range(10000)]<br \/>\nd1, d2, d3, d4 &#061; data.copy(), data.copy(), data.copy(), data.copy()<\/p>\n<p>def time_calc(func):<br \/>\n    def wrapper():<br \/>\n        start &#061; time.time()<br \/>\n        func()<br \/>\n        print(f&#034;{func.__name__} \u8017\u65f6: {time.time() &#8211; start:.4f}s&#034;)<br \/>\n    return wrapper<\/p>\n<p>&#064;time_calc<br \/>\ndef test_sorted():<br \/>\n    sorted(d1)<\/p>\n<p>&#064;time_calc<br \/>\ndef test_sort():<br \/>\n    d2.sort()<\/p>\n<p>&#064;time_calc<br \/>\ndef test_bubble():<br \/>\n    # \u5192\u6ce1\u6392\u5e8f&#xff08;\u4f18\u5316\u7248&#xff09;<br \/>\n    for i in range(len(d3)-1):<br \/>\n        for j in range(len(d3)-i-1):<br \/>\n            if d3[j] &gt; d3[j&#043;1]:<br \/>\n                d3[j], d3[j&#043;1] &#061; d3[j&#043;1], d3[j]<\/p>\n<p>&#064;time_calc<br \/>\ndef test_selection():<br \/>\n    # \u9009\u62e9\u6392\u5e8f<br \/>\n    for i in range(len(d4)-1):<br \/>\n        min_idx &#061; i<br \/>\n        for j in range(i&#043;1, len(d4)):<br \/>\n            if d4[j] &lt; d4[min_idx]:<br \/>\n                min_idx &#061; j<br \/>\n        if min_idx !&#061; i:<br \/>\n            d4[i], d4[min_idx] &#061; d4[min_idx], d4[i]<\/p>\n<p>test_sorted()    # \u6781\u5feb<br \/>\ntest_sort()      # \u6781\u5feb<br \/>\ntest_bubble()    # \u9f9f\u901f&#xff08;\u614e\u7528&#xff0c;\u53ef\u80fd\u8981\u51e0\u5341\u79d2&#xff09;<br \/>\ntest_selection() # \u8f83\u6162<\/p>\n<p>\u8fd0\u884c\u540e\u4f60\u4f1a\u76f4\u89c2\u611f\u53d7\u5230\u7b97\u6cd5\u65f6\u95f4\u590d\u6742\u5ea6\u5e26\u6765\u7684\u6027\u80fd\u5dee\u5f02&#xff0c;\u8fd9\u6b63\u662f\u88c5\u9970\u5668\u5728\u6027\u80fd\u76d1\u63a7\u4e2d\u7684\u5178\u578b\u5e94\u7528\u3002<\/p>\n<hr \/>\n<h3>5. \u5b9e\u6218\u6848\u4f8b&#xff08;\u4e8c&#xff09;&#xff1a;\u65e5\u5fd7\u8bb0\u5f55\u88c5\u9970\u5668&#xff08;\u4fdd\u5b58\u5230\u6587\u4ef6&#xff09;<\/h3>\n<p>\u5229\u7528\u00a0datetime\u00a0\u8bb0\u5f55\u51fd\u6570\u6267\u884c\u7684\u65f6\u95f4\u3001\u53c2\u6570\u548c\u8fd4\u56de\u503c&#xff0c;\u5e76\u5199\u5165TXT\u65e5\u5fd7\u3002<\/p>\n<p>from datetime import datetime<\/p>\n<p>def logger(func):<br \/>\n    def wrapper(*args, **kwargs):<br \/>\n        result &#061; func(*args, **kwargs)<br \/>\n        # \u62fc\u63a5\u65e5\u5fd7\u5185\u5bb9<br \/>\n        log_msg &#061; (f&#034;\u65f6\u95f4: {datetime.now().strftime(&#039;%Y-%m-%d %H:%M:%S&#039;)} | &#034;<br \/>\n                   f&#034;\u51fd\u6570: {func.__name__} | &#034;<br \/>\n                   f&#034;\u53c2\u6570: {args} {kwargs} | &#034;<br \/>\n                   f&#034;\u8fd4\u56de\u503c: {result}\\\\n&#034;)<br \/>\n        # \u5199\u5165\u6587\u4ef6&#xff08;\u8ffd\u52a0\u6a21\u5f0f&#xff09;<br \/>\n        with open(&#034;func_log.txt&#034;, &#034;a&#034;, encoding&#061;&#034;utf-8&#034;) as f:<br \/>\n            f.write(log_msg)<br \/>\n        return result<br \/>\n    return wrapper<\/p>\n<p>&#064;logger<br \/>\ndef max_value(a, b):<br \/>\n    return a if a &gt; b else b<\/p>\n<p>max_value(10, 20)<br \/>\nmax_value(100, 50)<\/p>\n<p>\u6253\u5f00\u540c\u76ee\u5f55\u4e0b\u7684\u00a0func_log.txt&#xff0c;\u4f60\u4f1a\u770b\u5230\u6e05\u6670\u7684\u8c03\u7528\u8bb0\u5f55\u3002<\/p>\n<hr \/>\n<h3>6. \u88c5\u9970\u5668\u5e26\u53c2\u6570&#xff08;\u4e09\u5c42\u5d4c\u5957&#xff09;<\/h3>\n<p>\u6709\u65f6\u6211\u4eec\u5e0c\u671b\u88c5\u9970\u5668\u672c\u8eab\u80fd\u63a5\u6536\u53c2\u6570&#xff08;\u5982\u6307\u5b9a\u65e5\u5fd7\u6587\u4ef6\u540d&#xff09;&#xff0c;\u9700\u8981\u518d\u5305\u4e00\u5c42\u3002<\/p>\n<p>def file_logger(filename):<br \/>\n    def decorator(func):<br \/>\n        def wrapper(*args, **kwargs):<br \/>\n            result &#061; func(*args, **kwargs)<br \/>\n            with open(filename, &#034;a&#034;) as f:<br \/>\n                f.write(f&#034;{func.__name__} \u6267\u884c\u5b8c\u6bd5\\\\n&#034;)<br \/>\n            return result<br \/>\n        return wrapper<br \/>\n    return decorator<\/p>\n<p>&#064;file_logger(&#034;app.log&#034;)<br \/>\ndef run_task():<br \/>\n    print(&#034;\u4efb\u52a1\u8fdb\u884c\u4e2d&#8230;&#034;)<\/p>\n<p>run_task()<\/p>\n<p>\u8fd9\u79cd\u201c\u88c5\u9970\u5668\u5de5\u5382\u201d\u5199\u6cd5\u5728\u5b9e\u9645\u6846\u67b6&#xff08;\u5982Flask\u8def\u7531&#xff09;\u4e2d\u975e\u5e38\u5e38\u89c1\u3002<\/p>\n<hr \/>\n<h3>\u7ed3\u8bed<\/h3>\n<p>\u95ed\u5305\u548c\u88c5\u9970\u5668\u662fPython\u8fdb\u9636\u8def\u4e0a\u7ed5\u4e0d\u5f00\u7684\u4e24\u5ea7\u5927\u5c71\u3002\u7406\u89e3\u95ed\u5305\u7684\u4e09\u8981\u7d20&#xff0c;\u4f60\u5c31\u80fd\u770b\u61c2\u4e00\u5207\u88c5\u9970\u5668\u7684\u6e90\u7801&#xff1b;\u638c\u63e1\u88c5\u9970\u5668\u7684\u5d4c\u5957\u673a\u5236&#xff0c;\u4f60\u5c31\u80fd\u5199\u51fa\u9ad8\u53ef\u7528\u7684\u65e5\u5fd7\u3001\u6743\u9650\u3001\u7f13\u5b58\u3001\u8ba1\u65f6\u7b49\u901a\u7528\u7ec4\u4ef6\u3002<\/p>\n<p>\u5efa\u8bae\u4f60\u4eb2\u624b\u628a\u6587\u4e2d\u7684\u4ee3\u7801\u6572\u4e00\u904d&#xff0c;\u89c2\u5bdf\u63a7\u5236\u53f0\u8f93\u51fa\u548c\u6587\u4ef6\u5199\u5165\u7ed3\u679c\u3002\u53ea\u6709\u52a8\u624b\u5b9e\u8df5&#xff0c;\u624d\u80fd\u771f\u6b63\u5185\u5316\u8fd9\u4e9b\u77e5\u8bc6&#xff01;<\/p>\n<p>\u5982\u679c\u8fd9\u7bc7\u6587\u7ae0\u5e2e\u5230\u4e86\u4f60&#xff0c;\u6b22\u8fce\u4e00\u952e\u4e09\u8fde&#xff0c;\u6211\u4eec\u4e0b\u671f\u89c1&#xff01;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00\u5982\u679c\u4f60\u5df2\u7ecf\u719f\u6089\u4e86\u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5&#xff0c;\u90a3\u4e48\u606d\u559c\u4f60\u6765\u5230Python\u8fdb\u9636\u7684\u5927\u95e8&#xff01;\u95ed\u5305&#xff08;Closure&#xff09;\u548c\u88c5\u9970\u5668&#xff08;Decorator&#xff09;\u662fPython\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u7cbe\u9ad3&#xff0c;\u4e5f\u662f\u9762\u8bd5\u4e2d\u7ed5\u4e0d\u5f00\u7684\u9ad8\u9891\u8003\u70b9\u3002\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790\u95ed\u5305\u7684\u201c\u4e09\u8981\u7d20\u201d&#xff0c;\u5e76\u5e26\u4f60\u624b\u5199\u901a\u7528\u7684\u65e5\u5fd7\u88c5\u9970\u5668\u3001\u8ba1\u65f6\u88c5\u9970\u5668&#xff0c;\u8ba9\u4f60\u771f\u6b63\u7406\u89e3\u8bed\u6cd5\u7cd6\u80cc\u540e\u7684\u539f\u7406\u30021. \u95ed\u5305&#xff08;Closure&#xff09;\u2014\u2014 \u51fd\u6570<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[9099,81,190],"topic":[],"class_list":["post-82950","post","type-post","status-publish","format-standard","hentry","category-server","tag-9099","tag-python","tag-190"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/82950.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u524d\u8a00\u5982\u679c\u4f60\u5df2\u7ecf\u719f\u6089\u4e86\u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5&#xff0c;\u90a3\u4e48\u606d\u559c\u4f60\u6765\u5230Python\u8fdb\u9636\u7684\u5927\u95e8&#xff01;\u95ed\u5305&#xff08;Closure&#xff09;\u548c\u88c5\u9970\u5668&#xff08;Decorator&#xff09;\u662fPython\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u7cbe\u9ad3&#xff0c;\u4e5f\u662f\u9762\u8bd5\u4e2d\u7ed5\u4e0d\u5f00\u7684\u9ad8\u9891\u8003\u70b9\u3002\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790\u95ed\u5305\u7684\u201c\u4e09\u8981\u7d20\u201d&#xff0c;\u5e76\u5e26\u4f60\u624b\u5199\u901a\u7528\u7684\u65e5\u5fd7\u88c5\u9970\u5668\u3001\u8ba1\u65f6\u88c5\u9970\u5668&#xff0c;\u8ba9\u4f60\u771f\u6b63\u7406\u89e3\u8bed\u6cd5\u7cd6\u80cc\u540e\u7684\u539f\u7406\u30021. \u95ed\u5305&#xff08;Closure&#xff09;\u2014\u2014 \u51fd\u6570\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/82950.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-07-25T07:08:36+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/82950.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/82950.html\",\"name\":\"Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-07-25T07:08:36+00:00\",\"dateModified\":\"2026-07-25T07:08:36+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/82950.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/82950.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/82950.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/82950.html","og_locale":"zh_CN","og_type":"article","og_title":"Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u524d\u8a00\u5982\u679c\u4f60\u5df2\u7ecf\u719f\u6089\u4e86\u51fd\u6570\u7684\u57fa\u672c\u7528\u6cd5&#xff0c;\u90a3\u4e48\u606d\u559c\u4f60\u6765\u5230Python\u8fdb\u9636\u7684\u5927\u95e8&#xff01;\u95ed\u5305&#xff08;Closure&#xff09;\u548c\u88c5\u9970\u5668&#xff08;Decorator&#xff09;\u662fPython\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u7cbe\u9ad3&#xff0c;\u4e5f\u662f\u9762\u8bd5\u4e2d\u7ed5\u4e0d\u5f00\u7684\u9ad8\u9891\u8003\u70b9\u3002\u672c\u6587\u5c06\u6df1\u5165\u5256\u6790\u95ed\u5305\u7684\u201c\u4e09\u8981\u7d20\u201d&#xff0c;\u5e76\u5e26\u4f60\u624b\u5199\u901a\u7528\u7684\u65e5\u5fd7\u88c5\u9970\u5668\u3001\u8ba1\u65f6\u88c5\u9970\u5668&#xff0c;\u8ba9\u4f60\u771f\u6b63\u7406\u89e3\u8bed\u6cd5\u7cd6\u80cc\u540e\u7684\u539f\u7406\u30021. \u95ed\u5305&#xff08;Closure&#xff09;\u2014\u2014 \u51fd\u6570","og_url":"https:\/\/www.wsisp.com\/helps\/82950.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-07-25T07:08:36+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/82950.html","url":"https:\/\/www.wsisp.com\/helps\/82950.html","name":"Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-07-25T07:08:36+00:00","dateModified":"2026-07-25T07:08:36+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/82950.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/82950.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/82950.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python\u8fdb\u9636\u5fc5\u6740\u6280\u2014\u2014\u95ed\u5305\u4e09\u8981\u7d20\u4e0e\u88c5\u9970\u5668\u5b8c\u5168\u6307\u5357"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/82950","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=82950"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/82950\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=82950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=82950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=82950"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=82950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}