{"id":92989,"date":"2020-03-25T08:14:07","date_gmt":"2020-03-25T00:14:07","guid":{"rendered":"http:\/\/4563.org\/?p=92989"},"modified":"2020-03-25T08:14:07","modified_gmt":"2020-03-25T00:14:07","slug":"python-%e4%b8%ad%e7%bb%99%e5%87%bd%e6%95%b0%e6%8c%87%e5%ae%9a-attribute-%e6%98%af%e8%89%af%e5%a5%bd%e7%9a%84%e5%ae%9e%e8%b7%b5%e5%90%97","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=92989","title":{"rendered":"Python \u4e2d\u7ed9\u51fd\u6570\u6307\u5b9a attribute \u662f\u826f\u597d\u7684\u5b9e\u8df5\u5417?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u4e2d\u7ed9\u51fd\u6570\u6307\u5b9a attribute \u662f\u826f\u597d\u7684\u5b9e\u8df5\u5417?               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : raymanr <\/span>  <span><i><\/i> 23<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u5728\u770b\u7ed8\u5236\u51b3\u7b56\u6811\u4ee3\u7801\u65f6\u5019\u770b\u5230\u4f5c\u8005\u8fd9\u4e48\u7528, \u8fd9\u4e2a\u7a0d\u5fae\u6709\u70b9\u8fdd\u53cd\u4e86\u6211\u7684\u611f\u89c9, \u4f2a\u4ee3\u7801\u5927\u6982\u5982\u4e0b:<\/p>\n<pre><code>def plot_tree(tree):     fig_size = plot_tree.fig_size     offset = plot_tree.offset     plot_tree.offset = some_func(fig_size, offset)  # \u8fd9\u91cc\u7ed9\u51fd\u6570\u6307\u5b9a\u4e86 attr     for key in tree.keys():         if isinstance(tree[key], dict):             plot_tree(tree[key])         else:             plot_node(tree[key])                       def main():     tree = make_tree()     plot_tree.fig_size = size_func(tree)  # \u8fd9\u91cc\u7ed9\u51fd\u6570\u6307\u5b9a\u4e86 attr     plot_tree.offset = offset_func(tree)  # \u8fd9\u91cc\u7ed9\u51fd\u6570\u6307\u5b9a\u4e86 attr     plot_tree(tree) <\/code><\/pre>\n<p>\u6211\u89c9\u5f97\u4f3c\u4e4e\u628a\u5c5e\u6027\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\u66f4\u7b26\u5408\u5927\u90e8\u5206\u4eba\u9605\u8bfb\u4e60\u60ef?<br \/> \u8fd8\u662f\u6211\u6bb5\u4f4d\u4e0d\u591f?<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>9<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"995451\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8fd9\u4e48\u5199\u5c31\u662f\u61d2\u3002\u672c\u6765\u5199\u4e2a\u7c7b\u5c31\u5b8c\u4e8b\u4e86\uff0c\u975e\u8981\u641e anti-pattern \u3002<\/p>\n<p>\u4e09\u4e2a\u6708\u4ee5\u540e\u770b\u8fd9\u4e2a\u7a0b\u5e8f\u5c31\u662f\u81ed\u7684\u6ca1\u6cd5\u4fee\u6539\u7684\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"995452\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u89c1\u8fc7\u597d\u591a\u8bba\u6587\u4ee3\u7801\u3002<\/p>\n<p>\u5728 python \u91cc\u9762\u7528 functional pattern \u7684\u4e00\u4e9b\u9ad8\u9636\u6280\u5de7\uff08\u6bd4\u5982 monadic combinator \uff09\u4e5f\u5c31\u7b97\u4e86\uff0c\u5c31\u662f\u6389\u4e66\u888b\u5b50\u96be\u4ee5\u7406\u89e3\uff0c\u4f46\u662f\u4e0d\u770b\u5b9e\u73b0\u7ec6\u8282\u53ea\u770b\u63a5\u53e3\u4e5f\u4e0d\u662f\u4e0d\u80fd\u770b\u4ee3\u7801\uff0c\u53cd\u6b63\u662f\u65e0\u526f\u4f5c\u7528\u7684\u3002<\/p>\n<p>\u7ed9\u51fd\u6570\u8d4b\u4e88 context \u7136\u540e\u81ea\u5df1\u91cc\u9762\u7528\u6211\u4e5f\u4e0d\u662f\u6ca1\u89c1\u8fc7\uff0c\u4f46\u662f\u4e00\u822c\u662f\u5916\u9762\u5957\u4e2a\u51fd\u6570\uff0c\u8fd4\u56de\u91cc\u9762\u7684\u51fd\u6570\u3002\u628a\u5916\u90e8\u51fd\u6570\u7684\u53c2\u6570\u548c\u5c40\u90e8\u53d8\u91cf\u5f53\u95ed\u5305\u548c\u5185\u90e8\u51fd\u6570\u88f9\u5728\u4e00\u8d77\u800c\u5df2\uff0c\u6211\u4e5f\u4e0d\u662f\u6ca1\u5728\u522b\u7684\u7f16\u7a0b\u8bed\u8a00\u89c1\u8fc7\uff0c\u6bd4\u5982 JS \u3002\u5176\u5b9e\u4e5f\u662f\u61d2\uff0c\u4e0d\u60f3\u5199\u7c7b\uff0c\u4f46\u662f\u6ca1\u6709\u526f\u4f5c\u7528\uff0c\u4e5f\u80fd\u7528\uff0c\u53ea\u4e0d\u8fc7\u6ca1\u6709 IDE \u7684\u667a\u80fd\u63d0\u793a\u800c\u5df2\u3002\u53cd\u6b63\u641e\u5b66\u672f\u7684\u4e00\u822c\u4e5f\u61d2\u5f97\u5b66 IDE \u3002\uff08\u867d\u7136\u6b63\u7ecf\u4e0a IDE \u8fd8\u662f\u5f88\u9999\u7684\uff09<\/p>\n<p>\u6bd4\u5982 https:\/\/github.com\/openai\/glow\/blob\/master\/model.py#L141<br \/>&#8211; &#8211; &#8211; &#8211;<\/p>\n<p>\u4f46\u662f\u61d2\u5230\u8fd9\u79cd\u7a0b\u5ea6\u6211\u4e5f\u6ca1\u6cd5\u8bf4\u4ec0\u4e48\u4e86\uff0c\u8fd9\u4e2a\u526f\u4f5c\u7528\u592a\u5927\u4e86\u3002\u4e3b\u4f60\u8981\u8fd9\u4e48\u505a\uff0c\u4ee5\u540e\u51fa\u4e86 BUG \u8c03\u4e00\u5929\u53ef\u522b\u602a\u6211\u6ca1\u63d0\u9192\u4f60\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"995453\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : raymanr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ipwx <br \/>\u6211\u770b\u5230\u7684\u8fd9\u6bb5\u4ee3\u7801\u662f 2010 \u5e74\u7684\u4e86, \u4e5f\u4e0d\u6e05\u695a\u662f\u4e0d\u662f\u90a3\u65f6\u5019\u7684\u4e2a\u522b\u60c5\u51b5.<\/p>\n<p>\u8fd8\u6709\u6bd4\u5982 if \u5224\u65ad\u548c\u6267\u884c \u5199\u5728\u540c\u4e00\u884c, \u8d4b\u503c\u53d8\u91cf\u4f7f\u7528 ; \u5728\u540c\u4e00\u884c\u591a\u4e2a\u8d4b\u503c\u7b49\u60c5\u51b5<\/p>\n<p>\u6211\u8fd8\u6b63\u5728\u4e00\u70b9\u70b9\u7684\u8fb9\u6539\u8fb9\u5199\u81ea\u5df1\u7684\u7248\u672c, \u4e0d\u8fc7\u7ed9\u51fd\u6570\u6307\u5b9a attr \u8fd9\u79cd\u6211\u4ee5\u524d\u771f\u7684\u662f\u60f3\u90fd\u6ca1\u60f3\u8fc7, \u6240\u4ee5\u4e0a\u6765\u4e5f\u6c42\u8bc1\u4e0b\u8fd9\u4e2a\u5408\u9002\u4e0d                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"995454\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u524d\u4e00\u5e74\u4e0d\u662f\u5f88\u6d41\u884c\u6240\u8c13\u95ed\u5305\u4e48<br \/>\u8fd9\u5c31\u662f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"995455\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Vegetable <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u89c9\u5f97\u4e0d\u662f, \u4f46\u662f\u53ef\u4ee5\u8fd9\u4e48\u7528, \u53ea\u6709\u5728\u67d0\u4e9b\u5f88\u7279\u6b8a\u7684\u60c5\u51b5\u4e0b\u624d\u4f7f\u7528\u8fd9\u79cd\u65b9\u5f0f.<br \/>\u6bd4\u5982 <\/p>\n<p>https:\/\/docs.djangoproject.com\/en\/3.0\/ref\/contrib\/admin\/#django.contrib.admin.ModelAdmin.list_display                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"995456\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : raymanr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @julyclyde <br \/>\u6211\u4e00\u76f4\u4ee5\u4e3a\u95ed\u5305\u662f\u6307\u7684\u7528\u5de5\u5382\u51fd\u6570\u751f\u4ea7\u51fd\u6570\u7684\u505a\u6cd5<\/p>\n<p>\u4e0d\u8fc7\u4f60\u8fd9\u4e48\u4e00\u63d0\u6211\u5012\u662f\u60f3\u8d77\u6765\u4e86, js \u91cc\u9762\u597d\u50cf\u6709\u5229\u7528 function \u5c01\u88c5\u5bf9\u8c61\u7684\u64cd\u4f5c<\/p>\n<p>\u5982\u679c\u4e00\u4e2a function \u672c\u8eab\u518d\u7ed9\u4ed6\u6307\u5b9a\u4e00\u4e9b function \u4f5c\u4e3a attr , \u597d\u50cf\u662f\u6709\u90a3\u4e48\u70b9\u610f\u601d\u4e86<\/p>\n<p>\u554a, js \u771f\u662f\u6df7\u4e71\u90aa\u6076                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"995457\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ipwx <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @julyclyde \u8fd9\u4e0d\u662f\u95ed\u5305\u3002\u4f60\u770b\u6211\u7ed9\u7684\u8fde\u63a5\u624d\u53eb\u95ed\u5305\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"995458\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @raymanr \u4f60\u8fd9\u56db\u4e2a\u5b57\u771f\u662f\u603b\u7ed3\u7684\u597d                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"995459\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : julyclyde <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ipwx \u597d\u7684\uff0c\u6211\u770b\u770b\u4f60\u8fd9\u4e2a\u94fe\u63a5\u3002\u591a\u8c22                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u4e2d\u7ed9\u51fd\u6570\u6307\u5b9a att&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/92989"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92989"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/92989\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92989"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92989"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92989"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}