{"id":277692,"date":"2021-01-13T18:53:02","date_gmt":"2021-01-13T10:53:02","guid":{"rendered":"http:\/\/4563.org\/?p=277692"},"modified":"2021-01-13T18:53:02","modified_gmt":"2021-01-13T10:53:02","slug":"python-%e9%81%87%e5%88%b0%e4%b8%80%e4%b8%aa%e5%88%97%e8%a1%a8%e9%97%ae%e9%a2%98%ef%bc%8c%e6%84%9f%e8%a7%89%e5%be%88%e5%a5%87%e6%80%aa%ef%bc%8c%e4%b9%9f%e4%b8%8d%e7%9f%a5%e9%81%93%e6%80%8e%e4%b9%88-goo","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=277692","title":{"rendered":"Python \u9047\u5230\u4e00\u4e2a\u5217\u8868\u95ee\u9898\uff0c\u611f\u89c9\u5f88\u5947\u602a\uff0c\u4e5f\u4e0d\u77e5\u9053\u600e\u4e48 Google\uff0c\u5e0c\u671b\u8001\u54e5\u4eec\u5e2e\u5fd9\u770b\u770b"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  Python \u9047\u5230\u4e00\u4e2a\u5217\u8868\u95ee\u9898\uff0c\u611f\u89c9\u5f88\u5947\u602a\uff0c\u4e5f\u4e0d\u77e5\u9053\u600e\u4e48 Google\uff0c\u5e0c\u671b\u8001\u54e5\u4eec\u5e2e\u5fd9\u770b\u770b               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : wangyzj <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u73af\u5883\u4e3a python3.5\uff0cubuntu1604 \u770b\u5230\u4e00\u4e2a\u5e93\u4e2d\u5bf9 list \u505a\u4e86\u7ee7\u627f \u4ee3\u7801\u5927\u610f\u5982\u4e0b<\/p>\n<p>\u5728\u770b\u524d\u4eba\u4ee3\u7801\u7684\u65f6\u5019\u53d1\u73b0\u5bf9\u65b9\u4f7f\u7528 NewList([1,2,3], 3)[&#8216;total&#8217;]\u8fd9\u7c7b\u8bed\u6cd5\u83b7\u5f97\u6b63\u786e\u8f93\u51fa \u4f46 l = NewList([1,2,3], 3)\u540e l.total \u662f\u6b63\u786e\u8f93\u51fa\u7684 l[&#8216;total&#8217;]\u662f\u62a5\u9519\u5f97\uff1alist indices must be integers or slices \u4e0d\u77e5\u9053\u5e94\u8be5\u600e\u4e48\u89e3\u91ca\u8fd9\u79cd\u60c5\u51b5<\/p>\n<pre><code>class NewList(list):      def __init__(self, iterable=None, _total=0):         if iterable is not None:             list.__init__(self, iterable)         else:             list.__init__(self)          self.total = _total          self.iterable = iterable or []      next = __next__ <\/code><\/pre>\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=\"4923482\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : geebos <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6211\u8bd5\u4e86\u4e00\u4e0b\uff0c\u7b2c\u4e00\u79cd\u4e5f\u662f\u62a5\u9519\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923483\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyzj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @geebos #1 \u53ef\u80fd\u662f\u6211\u7684 sample \u4e0d\u51c6\u786e\u5427\uff0c\u4e0d\u8fc7\u6211\u4e5f\u6ca1\u53d1\u73b0\u5176\u4ed6\u5173\u952e\u7684\u70b9<br \/>\u4f46\u6211\u7684\u786e\u9047\u5230\u4e86\u8fd9\u79cd\u95ee\u9898\uff0c\u5f88\u5947\u602a<br \/>\u7406\u8bba\u4e0a\u62a5\u9519\u662f\u5bf9\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923484\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ManjusakaL <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u8bd5\u4e00\u4e0b<\/p>\n<p>&#8220;`python<br \/>a = list()<br \/>a[&#8216;total&#8217;]<br \/>&#8220;` <\/p>\n<p>\u4e0d\u5c31\u61c2\u4e86\u3002\u3002<\/p>\n<p>\u8981\u7406\u89e3\u7684\u66f4\u6e05\u695a\u53bb\u80cc\u8bf5\u4e00\u4e0b Python Document \u4e2d Language Reference Chap 3 Data Model \u8fd9\u7ae0\u4f60\u5c31\u61c2\u4e86                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923485\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : skinny <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f60\u8fd9\u65e2\u4e0d\u662f mapping \u5bf9\u8c61\u4e5f\u6ca1\u6709\u5b9e\u73b0\u81ea\u5df1\u7684__getitem__\u65b9\u6cd5\u5f53\u7136\u4f1a\u62a5\u9519\uff0ctutorial \u591a\u8bfb\u51e0\u904d\u2026\u2026                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923486\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : chenqh <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u611f\u89c9\u662f\u590d\u5199\u4e86 __getitem__, .\u7684\u5199\u6cd5\u9700\u8981 override __getattr__\u5427                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923487\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nthhdy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             &gt; \u5728\u770b\u524d\u4eba\u4ee3\u7801\u7684\u65f6\u5019\u53d1\u73b0\u5bf9\u65b9\u4f7f\u7528 NewList([1,2,3], 3)[&#8216;total&#8217;]\u8fd9\u7c7b\u8bed\u6cd5\u83b7\u5f97\u6b63\u786e\u8f93\u51fa<\/p>\n<p>\u4e0d\u5e94\u8be5\u5427\uff0c\u518d\u8bfb\u8bfb\uff0c\u771f\u5b9e\u8fd0\u884c\u4e00\u4e0b\u3002\u770b\u662f\u4e0d\u662f\u7406\u89e3\u6709\u8bef\u3002\u5982\u679c\u8fd9\u91cc\u7684 NewList \u771f\u662f\u50cf\u8d34\u51fa\u6765\u7684\u4ee3\u7801\u8fd9\u6837\u5b9a\u4e49\u7684\uff0c\u8fd9\u4e2a\u8868\u8fbe\u5f0f\u540c\u6837\u4f1a\u62a5\u9519\u7684\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923488\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : wangyzj <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @nthhdy #6 \u4f46\u662f\u5982\u679c\u6709\u4e86 getitem \u5b9e\u73b0\u7684\u8bdd\u4e0d\u5e94\u8be5\u5355\u72ec\u8d4b\u503c\u4e00\u4e2a\u65b0\u7684 var \u540e\u6267\u884c[&#8216;total&#8217;]\u62a5\u9519                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923489\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zhanglintc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u60f3\u60f3\u4e0d\u5e94\u8be5\u4f1a\u53d1\u751f\u8fd9\u79cd\u73b0\u8c61\u554a, \u65e0\u8bba `NewList()` \u4ea7\u751f\u7684\u5bf9\u8c61\u662f\u5426\u8d4b\u503c\u7ed9 `l`, \u5b83\u90fd\u662f\u540c\u4e00\u4e2a\u7c7b\u578b\u7684 `NewList` \u5bf9\u8c61, \u4e0d\u5e94\u8be5\u5f71\u54cd\u5b83\u7684\u5c5e\u6027\u8c03\u7528\u65b9\u5f0f\u4ec0\u4e48\u7684.<\/p>\n<p>\u5982\u679c\u4f60\u7ed9\u7684\u4f8b\u5b50\u7684\u8f93\u51fa\u7684\u786e\u6ca1\u6709\u95ee\u9898\u7684\u8bdd, \u90a3\u8fd9\u5012\u662f\u4e2a\u633a\u6709\u610f\u601d\u7684\u95ee\u9898. \u4e3b\u53ef\u4ee5\u518d\u8fd0\u884c\u4e0b\u8d34\u70b9\u7ed3\u679c\u8bc1\u660e\u7684\u786e\u662f\u8fd9\u4e2a\u73b0\u8c61\u4e48.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"4923490\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : nthhdy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @wangyzj \u4f60\u8d34\u7684\u5b9e\u73b0\u6ca1\u6709 `__getitem__` \u65b9\u6cd5\uff0c\u5c31\u4f1a\u7528 list \u7684\u8be5\u65b9\u6cd5\uff0c\u4f46\u662f list \u4e0b\u6807\u4e0d\u80fd\u63a5\u53d7\u5b57\u7b26\u4e32\uff0c\u629b\u51fa\u8fd9\u4e2a\u5f02\u5e38\u5f88\u6b63\u5e38\u3002\u5c31\u50cf\u5bf9 `[][&#8216;a&#8217;]` \u8fdb\u884c\u6c42\u503c\u629b\u51fa\u7684\u5f02\u5e38\u4e00\u6837\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>Python \u9047\u5230\u4e00\u4e2a\u5217\u8868\u95ee\u9898\uff0c\u611f&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\/277692"}],"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=277692"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/277692\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=277692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=277692"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=277692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}