{"id":957,"date":"2010-12-14T17:07:27","date_gmt":"2010-12-14T08:07:27","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=957"},"modified":"2010-12-15T10:02:53","modified_gmt":"2010-12-15T01:02:53","slug":"%e3%83%87%e3%82%b3%e3%83%ac%e3%83%bc%e3%82%bf%e9%96%a2%e9%80%a3%e3%81%a7%e5%88%86%e3%81%8b%e3%81%a3%e3%81%9f%e4%ba%8b","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/957","title":{"rendered":"\u30c7\u30b3\u30ec\u30fc\u30bf\u95a2\u9023\u3067\u5206\u304b\u3063\u305f\u4e8b"},"content":{"rendered":"<p>\u6628\u65e5\u304b\u3089\u30c7\u30b3\u30ec\u30fc\u30bf\u306b\u3064\u3044\u3066\u8272\u3005\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u306a\u304c\u3089\u8abf\u3079\u3066\u3066\u5206\u304b\u3063\u305f\u4e8b\u3067\u3059\u3002\u30c7\u30b3\u30ec\u30fc\u30bf\u306b\u9650\u3089\u306a\u3044\u90e8\u5206\u3082\u591a\u3005\u3002<\/p>\n<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/946\">\u6628\u65e5\u66f8\u3044\u305f\u30c7\u30b3\u30ec\u30fc\u30bf\u306e\u8a71<\/a>\u3067\u3001\u30c7\u30b3\u30ec\u30fc\u30bf\u5185\u3067\u72b6\u614b\u3092\u4fdd\u6301\u3059\u308b\u305f\u3081\u306b\u3001\u300cf.call_count = -1\u300d\u307f\u305f\u3044\u306b\u66f8\u3044\u305f\u3051\u3069\u3001\u672c\u5f53\u306f\u666e\u901a\u306b\u8003\u3048\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u305f\u304b\u3063\u305f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef negligence(n):\r\n\tdef _(f):\r\n\t\tcall_count = -1\r\n\t\tdef __(*args, **kwargs):\r\n\t\t\tcall_count += 1\r\n\t\t\tif call_count % n == 0:\r\n\t\t\t\tcall_count = 0\r\n\t\t\t\treturn f(*args, **kwargs)\r\n\t\treturn __\r\n\treturn _\r\n<\/pre>\n<p>\u3067\u3082\u30b3\u30ec\u3060\u3068\u95a2\u6570\u306e\u5b9f\u884c\u6642&#8221;__(*args, **kwargs)&#8221;\u306e\u5b9f\u884c\u6642\u306bUnboundLocalError\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f&#8221;__(*args, **kwargs)&#8221;\u306e\u6700\u521d\u306e&#8221;call_count += 1&#8243;\u3067\u30d6\u30ed\u30c3\u30af\u5916\u306e\u5909\u6570\u306e\u53c2\u7167\u3068\u4ee3\u5165\u304c\u884c\u308f\u308c\u308b\u304b\u3089\u3067\u3059\u3002<br \/>\n\u30d6\u30ed\u30c3\u30af\u5185\u3067\u4ee3\u5165\u3060\u3051\uff08\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306e\u4f5c\u6210\uff09\u3084\u53c2\u7167\u3060\u3051\uff08\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u5909\u6570\u306e\u53c2\u7167\uff09\u3084\u4ee3\u5165\u5f8c\u53c2\u7167\uff08\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306e\u5229\u7528\uff09\u306a\u3089\u4f8b\u5916\u306f\u767a\u751f\u3057\u307e\u305b\u3093\u3002<br \/>\n\u53c2\u7167\u5f8c\u4ee3\u5165\u3067\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3059\u3002\uff08<a href=\"http:\/\/d.hatena.ne.jp\/octech\/20070803\" target=\"_blank\">\u8a73\u7d30<\/a>\uff09<\/p>\n<p>UnboundLocalError\u3092\u767a\u751f\u3055\u305b\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u306b\u306f\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef negligence(n):\r\n\tdef _(f):\r\n\t\tstatus = dict(call_count = -1)\r\n\t\tdef __(*args, **kwargs):\r\n\t\t\tstatus&#x5B;'call_count'] += 1\r\n\t\t\tif status&#x5B;'call_count'] % n == 0:\r\n\t\t\t\tstatus&#x5B;'call_count'] = 0\r\n\t\t\t\treturn f(*args, **kwargs)\r\n\t\treturn __\r\n\treturn _\r\n<\/pre>\n<p>\u3053\u306e\u4f8b\u3067\u306f&#8221;__(*args, **kwargs)&#8221;\u306e\u4e00\u3064\u4e0a\u306e\u30d6\u30ed\u30c3\u30af\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308bstatus\u3068\u3044\u3046\u5909\u6570\u306b\u76f4\u63a5\u4ee3\u5165\u3057\u3066\u306a\u3044\u305f\u3081\u3046\u307e\u304f\u52d5\u304d\u307e\u3059\u3002<\/p>\n<p>\u8a71\u306f\u3061\u3087\u3063\u3068\u5909\u308f\u308a\u307e\u3059\u304c\u3001\u6628\u65e5\u66f8\u3044\u305f\u8a18\u4e8b\u3067callable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u30c7\u30b3\u30ec\u30fc\u30bf\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u5931\u6557\u4f5c\u3068\u3057\u3066\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c\u3001\u305d\u306e\u9006\u3082\u53ef\u80fd\u306a\u3093\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u3064\u307e\u308a\u3001\u300ccallable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059&#8221;\u95a2\u6570\u3067\u5b9f\u88c5\u3055\u308c\u305f&#8221;\u30c7\u30b3\u30ec\u30fc\u30bf\u300d\u306e\u9006\u306e\u300c\u95a2\u6570\u3092\u8fd4\u3059&#8221;\u30af\u30e9\u30b9\u3067\u5b9f\u88c5\u3055\u308c\u305f&#8221;\u30c7\u30b3\u30ec\u30fc\u30bf\u300d\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nclass negligence(object):\r\n\tdef __init__(self, n):\r\n\t\tself.__n = n\r\n\t\tself.__call_count = -1\r\n\tdef __call__(self, f):\r\n\t\tself.__f = f\r\n\t\tdef _(*args, **kwargs):\r\n\t\t\tself.__call_count += 1\r\n\t\t\tif self.__call_count % self.__n == 0:\r\n\t\t\t\tself.__call_count = 0\r\n\t\t\t\treturn self.__f(*args, **kwargs)\r\n<\/pre>\n<p>\u3053\u308c\u3082\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u307e\u3057\u305f\u3002<br \/>\n\u4f55\u3082\u76ee\u65b0\u3057\u3044\u30d1\u30bf\u30fc\u30f3\u3067\u306f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u72b6\u614b\u3092\u4fdd\u6301\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u30c7\u30b3\u30ec\u30fc\u30bf\u3067\u306f\u3053\u3061\u3089\u3092\u4f7f\u3063\u305f\u65b9\u304c\u6df7\u4e71\u306f\u5c11\u306a\u3044\u304b\u3082\u3002<\/p>\n<p>\u3042\u3068\u3001\u6628\u65e5\u66f8\u3044\u305f\u5931\u6557\u4f5c\uff08callable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u30d1\u30bf\u30fc\u30f3\u306e\u30c7\u30b3\u30ec\u30fc\u30bf\uff09\u304c\u30e1\u30bd\u30c3\u30c9\u306b\u9069\u7528\u3059\u308b\u3068\u3046\u307e\u304f\u52d5\u4f5c\u3057\u306a\u3044\u7406\u7531\u3092\u3082\u3046\u3061\u3087\u3063\u3068\u3002<br \/>\nclass\u6587\u306e\u30d6\u30ed\u30c3\u30af\u76f4\u4e0b\u306e\u95a2\u6570\u306f\u901a\u5e38\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3067bound method\u5316\u3059\u308b\u3051\u3069\u3001callable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u3066\u3082callable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u307e\u307e\u306a\u305f\u3081\u3001bound method\u3067\u306f\u5f53\u7136\u53d7\u3051\u53d6\u308c\u308b\u306f\u305a\u306e\u7b2c\u4e00\u5f15\u6570\u306eself\u304c\u53d7\u3051\u53d6\u308c\u306a\u3044\u3068\u3044\u3046\u4e8b\u306b\u306a\u308b\u307f\u305f\u3044\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6628\u65e5\u304b\u3089\u30c7\u30b3\u30ec\u30fc\u30bf\u306b\u3064\u3044\u3066\u8272\u3005\u30c6\u30b9\u30c8\u30b3\u30fc\u30c9\u3092\u66f8\u304d\u306a\u304c\u3089\u8abf\u3079\u3066\u3066\u5206\u304b\u3063\u305f\u4e8b\u3067\u3059\u3002\u30c7\u30b3\u30ec\u30fc\u30bf\u306b\u9650\u3089\u306a\u3044\u90e8\u5206\u3082\u591a\u3005\u3002<\/p>\n<p><a href=\"https:\/\/peta.okechan.net\/blog\/archives\/946\">\u6628\u65e5\u66f8\u3044\u305f\u30c7\u30b3\u30ec\u30fc\u30bf\u306e\u8a71<\/a>\u3067\u3001\u30c7\u30b3\u30ec\u30fc\u30bf\u5185\u3067\u72b6\u614b\u3092\u4fdd\u6301\u3059\u308b\u305f\u3081\u306b\u3001\u300cf.call_count = -1\u300d\u307f\u305f\u3044\u306b\u66f8\u3044\u305f\u3051\u3069\u3001\u672c\u5f53\u306f\u666e\u901a\u306b\u8003\u3048\u3066\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u305f\u304b\u3063\u305f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef negligence(n):\r\n\tdef _(f):\r\n\t\tcall_count = -1\r\n\t\tdef __(*args, **kwargs):\r\n\t\t\tcall_count += 1\r\n\t\t\tif call_count % n == 0:\r\n\t\t\t\tcall_count = 0\r\n\t\t\t\treturn f(*args, **kwargs)\r\n\t\treturn __\r\n\treturn _\r\n<\/pre>\n<p>\u3067\u3082\u30b3\u30ec\u3060\u3068\u95a2\u6570\u306e\u5b9f\u884c\u6642&#8221;__(*args, **kwargs)&#8221;\u306e\u5b9f\u884c\u6642\u306bUnboundLocalError\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f&#8221;__(*args, **kwargs)&#8221;\u306e\u6700\u521d\u306e&#8221;call_count += 1&#8243;\u3067\u30d6\u30ed\u30c3\u30af\u5916\u306e\u5909\u6570\u306e\u53c2\u7167\u3068\u4ee3\u5165\u304c\u884c\u308f\u308c\u308b\u304b\u3089\u3067\u3059\u3002<br \/>\n\u30d6\u30ed\u30c3\u30af\u5185\u3067\u4ee3\u5165\u3060\u3051\uff08\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306e\u4f5c\u6210\uff09\u3084\u53c2\u7167\u3060\u3051\uff08\u4e0a\u4f4d\u30d6\u30ed\u30c3\u30af\u306e\u5909\u6570\u306e\u53c2\u7167\uff09\u3084\u4ee3\u5165\u5f8c\u53c2\u7167\uff08\u30ed\u30fc\u30ab\u30eb\u5909\u6570\u306e\u5229\u7528\uff09\u306a\u3089\u4f8b\u5916\u306f\u767a\u751f\u3057\u307e\u305b\u3093\u3002<br \/>\n\u53c2\u7167\u5f8c\u4ee3\u5165\u3067\u4f8b\u5916\u304c\u767a\u751f\u3057\u307e\u3059\u3002\uff08<a href=\"http:\/\/d.hatena.ne.jp\/octech\/20070803\" target=\"_blank\">\u8a73\u7d30<\/a>\uff09<\/p>\n<p>UnboundLocalError\u3092\u767a\u751f\u3055\u305b\u306a\u3044\u3088\u3046\u306b\u3059\u308b\u306b\u306f\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u66f8\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef negligence(n):\r\n\tdef _(f):\r\n\t\tstatus = dict(call_count = -1)\r\n\t\tdef __(*args, **kwargs):\r\n\t\t\tstatus&#x5B;'call_count'] += 1\r\n\t\t\tif status&#x5B;'call_count'] % n == 0:\r\n\t\t\t\tstatus&#x5B;'call_count'] = 0\r\n\t\t\t\treturn f(*args, **kwargs)\r\n\t\treturn __\r\n\treturn _\r\n<\/pre>\n<p>\u3053\u306e\u4f8b\u3067\u306f&#8221;__(*args, **kwargs)&#8221;\u306e\u4e00\u3064\u4e0a\u306e\u30d6\u30ed\u30c3\u30af\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308bstatus\u3068\u3044\u3046\u5909\u6570\u306b\u76f4\u63a5\u4ee3\u5165\u3057\u3066\u306a\u3044\u305f\u3081\u3046\u307e\u304f\u52d5\u304d\u307e\u3059\u3002<\/p>\n<p>\u8a71\u306f\u3061\u3087\u3063\u3068\u5909\u308f\u308a\u307e\u3059\u304c\u3001\u6628\u65e5\u66f8\u3044\u305f\u8a18\u4e8b\u3067callable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u30c7\u30b3\u30ec\u30fc\u30bf\u306e\u30d1\u30bf\u30fc\u30f3\u3092\u5931\u6557\u4f5c\u3068\u3057\u3066\u7d39\u4ecb\u3057\u307e\u3057\u305f\u304c\u3001\u305d\u306e\u9006\u3082\u53ef\u80fd\u306a\u3093\u3067\u306f\u306a\u3044\u304b\u3068\u601d\u3044\u8a66\u3057\u3066\u307f\u307e\u3057\u305f\u3002<br \/>\n\u3064\u307e\u308a\u3001\u300ccallable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059&#8221;\u95a2\u6570\u3067\u5b9f\u88c5\u3055\u308c\u305f&#8221;\u30c7\u30b3\u30ec\u30fc\u30bf\u300d\u306e\u9006\u306e\u300c\u95a2\u6570\u3092\u8fd4\u3059&#8221;\u30af\u30e9\u30b9\u3067\u5b9f\u88c5\u3055\u308c\u305f&#8221;\u30c7\u30b3\u30ec\u30fc\u30bf\u300d\u3067\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nclass negligence(object):\r\n\tdef __init__(self, n):\r\n\t\tself.__n = n\r\n\t\tself.__call_count = -1\r\n\tdef __call__(self, f):\r\n\t\tself.__f = f\r\n\t\tdef _(*args, **kwargs):\r\n\t\t\tself.__call_count += 1\r\n\t\t\tif self.__call_count % self.__n == 0:\r\n\t\t\t\tself.__call_count = 0\r\n\t\t\t\treturn self.__f(*args, **kwargs)\r\n<\/pre>\n<p>\u3053\u308c\u3082\u6b63\u5e38\u306b\u52d5\u4f5c\u3057\u307e\u3057\u305f\u3002<br \/>\n\u4f55\u3082\u76ee\u65b0\u3057\u3044\u30d1\u30bf\u30fc\u30f3\u3067\u306f\u306a\u3044\u3068\u601d\u3044\u307e\u3059\u304c\u3001\u72b6\u614b\u3092\u4fdd\u6301\u3059\u308b\u5fc5\u8981\u304c\u3042\u308b\u30c7\u30b3\u30ec\u30fc\u30bf\u3067\u306f\u3053\u3061\u3089\u3092\u4f7f\u3063\u305f\u65b9\u304c\u6df7\u4e71\u306f\u5c11\u306a\u3044\u304b\u3082\u3002<\/p>\n<p>\u3042\u3068\u3001\u6628\u65e5\u66f8\u3044\u305f\u5931\u6557\u4f5c\uff08callable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8fd4\u3059\u30d1\u30bf\u30fc\u30f3\u306e\u30c7\u30b3\u30ec\u30fc\u30bf\uff09\u304c\u30e1\u30bd\u30c3\u30c9\u306b\u9069\u7528\u3059\u308b\u3068\u3046\u307e\u304f\u52d5\u4f5c\u3057\u306a\u3044\u7406\u7531\u3092\u3082\u3046\u3061\u3087\u3063\u3068\u3002<br \/>\nclass\u6587\u306e\u30d6\u30ed\u30c3\u30af\u76f4\u4e0b\u306e\u95a2\u6570\u306f\u901a\u5e38\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u305f\u30bf\u30a4\u30df\u30f3\u30b0\u3067bound method\u5316\u3059\u308b\u3051\u3069\u3001callable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5316\u3055\u308c\u3066\u3082callable\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u307e\u307e\u306a\u305f\u3081\u3001bound method\u3067\u306f\u5f53\u7136\u53d7\u3051\u53d6\u308c\u308b\u306f\u305a\u306e\u7b2c\u4e00\u5f15\u6570\u306eself\u304c\u53d7\u3051\u53d6\u308c\u306a\u3044\u3068\u3044\u3046\u4e8b\u306b\u306a\u308b\u307f\u305f\u3044\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[60],"class_list":["post-957","post","type-post","status-publish","format-standard","hentry","category-tech","tag-python"],"_links":{"self":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/comments?post=957"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/957\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=957"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}