{"id":946,"date":"2010-12-13T18:11:27","date_gmt":"2010-12-13T09:11:27","guid":{"rendered":"http:\/\/peta.okechan.net\/blog\/?p=946"},"modified":"2010-12-13T23:38:31","modified_gmt":"2010-12-13T14:38:31","slug":"%e6%89%8b%e6%8a%9c%e3%81%8d%e3%82%92%e3%81%99%e3%82%8b%e3%83%87%e3%82%b3%e3%83%ac%e3%83%bc%e3%82%bf","status":"publish","type":"post","link":"https:\/\/peta.okechan.net\/blog\/archives\/946","title":{"rendered":"\u624b\u629c\u304d\u3092\u3059\u308b\u30c7\u30b3\u30ec\u30fc\u30bf"},"content":{"rendered":"<p>n\u56de\u306e\u547c\u3073\u51fa\u3057\u306e\u3046\u30611\u56de\u3057\u304b\u5b9f\u969b\u306e\u51e6\u7406\u3092\u884c\u308f\u306a\u3044\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u8003\u3048\u3066\u307f\u305f\u3002<br \/>\n\uff08Zinnia\u3092\u4f7f\u3063\u3066\u624b\u66f8\u304d\u6587\u5b57\u3092\u8a8d\u8b58\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u305f\u3068\u304d\u306b\u3001\u30da\u30f3\u306e\u63cf\u753b\uff08\u30de\u30a6\u30b9\u306e\u30c9\u30e9\u30c3\u30b0\uff09\u30a4\u30d9\u30f3\u30c8\u304c\u7269\u51c4\u3044\u56de\u6570\u8d77\u304d\u3066\u3082\u5ea7\u6a19\u30c7\u30fc\u30bf\u304c\u5897\u5927\u3059\u308b\u3060\u3051\u3067\u7cbe\u5ea6\u306f\u3042\u307e\u308a\u4e0a\u304c\u3089\u306a\u3044\u3093\u3058\u3083\u306a\u3044\u304b\u3068\u601d\u3044\u3001\u7a0b\u826f\u304f\u51e6\u7406\u56de\u6570\u3092\u6e1b\u3089\u3059\u305f\u3081\u8003\u3048\u305f\u3002\uff09<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef negligence(n):\r\n\tu'''n\u56de\u306b1\u56de\u3057\u304b\u51e6\u7406\u3057\u306a\u3044\u30c7\u30b3\u30ec\u30fc\u30bf'''\r\n\r\n\tdef _(f):\r\n\t\tf.call_count = -1\r\n\t\tdef __(*args, **kwargs):\r\n\t\t\tf.call_count += 1\r\n\t\t\tif f.call_count % n == 0:\r\n\t\t\t\tf.call_count = 0\r\n\t\t\t\treturn f(*args, **kwargs)\r\n\t\treturn __\r\n\treturn _\r\n<\/pre>\n<p>\u4f7f\u3044\u65b9<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nclass negtest(object):\r\n\t@negligence(3)\r\n\tdef test(self, text): \r\n\t\tprint text\r\n\r\n@negligence(5)\r\ndef nttest(text):\r\n\tprint text\r\n\r\nnt = negtest()\r\nfor i in range(10):\r\n\tnt.test('test%d' % i)\r\n\r\nprint\r\n\r\nfor i in range(15):\r\n\tnttest('test%d' %i)\r\n\r\n# \u5b9f\u884c\u7d50\u679c\r\ntest0\r\ntest3\r\ntest6\r\ntest9\r\n\r\ntest0\r\ntest5\r\ntest10\r\n<\/pre>\n<p>\u6ce8\u610f\u70b9<br \/>\n\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306bcall_count\u3068\u3044\u3046\u5c5e\u6027\u3092\u8ffd\u52a0\u3057\u3066\u308b\u306e\u3067\u30d0\u30c3\u30c6\u30a3\u30f3\u30b0\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<br \/>\n\u51e6\u7406\u3057\u306a\u304b\u3063\u305f\u5834\u5408\u306e\u623b\u308a\u5024\u3068\u3057\u3066None\u304c\u8fd4\u3063\u3066\u304f\u308b\u305f\u3081\u3001\u547c\u3073\u51fa\u3057\u5074\u3067\u305d\u308c\u3092\u8003\u616e\u3057\u3066\u306a\u3044\u3068\u554f\u984c\u304c\u8d77\u304d\u308b\u304b\u3082\u3002\uff08\u623b\u308a\u5024\u3092\u4f7f\u3046\u90e8\u5206\u3067\u51e6\u7406\u3092\u7701\u304d\u305f\u304b\u3063\u305f\u3089Memoize\uff01\uff09<br \/>\n\u3068\u3044\u3046\u304b\u3001\u305d\u3082\u305d\u3082\u56fa\u5b9a\u7684\u306b\u51e6\u7406\u56de\u6570\u3092\u6e1b\u3089\u3057\u305f\u3044\u4e8b\u3063\u3066\u3042\u307e\u308a\u7121\u3044\u3088\u3046\u306aw \u7279\u306b\u307e\u3068\u3082\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u306a\u308c\u3070\u306a\u308b\u307b\u3069\u3002<\/p>\n<p>\u5931\u6557\u4f5c<br \/>\n\u547c\u3073\u51fa\u3057\u56de\u6570\u3068\u3044\u3046\u72b6\u614b\u3092\u6301\u3064\u305f\u3081\u3001\u6700\u521d\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30af\u30e9\u30b9\u3092\u8fd4\u3059\u30c7\u30b3\u30ec\u30fc\u30bf\u3067\u5b9f\u88c5\u3057\u3066\u305f\u3051\u3069\u3001function\u306e\u5834\u5408\u3001bound method\u306e\u5834\u5408\u3001unbound method\u306e\u5834\u5408\u3001\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u5834\u5408\u306e\u3059\u3079\u3066\u3067\u753b\u4e00\u7684\u306a\u65b9\u6cd5\u3067\u6b63\u5e38\u306b\u52d5\u4f5c\u3055\u305b\u308b\u65b9\u6cd5\u304c\u5206\u304b\u3089\u305a\u65ad\u5ff5\u3002<br \/>\nsys._getframe\u3068\u304b\u4f7f\u3063\u3066\u307f\u305f\u3051\u3069\u3001\u305d\u308c\u305e\u308c\u306e\u5834\u5408\u3067\u3046\u307e\u304f\u52d5\u304f\u65b9\u6cd5\u304c\u3042\u3063\u305f\u3068\u3057\u3066\u3082\u3001\u6fc0\u3057\u304f\u5834\u5408\u5206\u3051\u304c\u5fc5\u8981\u306a\u4e88\u611f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef negligence(n):\r\n\tu'''n\u56de\u306b1\u56de\u3057\u304b\u51e6\u7406\u3057\u306a\u3044\u30c7\u30b3\u30ec\u30fc\u30bf'''\r\n\t\r\n\tclass _(object):\r\n\t\t\r\n\t\tdef __init__(self, f):\r\n\t\t\tself.__f = f\r\n\t\t\tself.__call_count = -1\r\n\t\t\r\n\t\tdef __call__(self, *args, **kwargs):\r\n\t\t\tself.__call_count += 1\r\n\t\t\tif self.__call_count % n == 0:\r\n\t\t\t\tself.__call_count = 0\r\n\t\t\t\treturn self.__f(*args, **kwargs)\r\n\treturn _\r\n<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3053\u306e\u4f8b\u3060\u3068function\u306b\u3057\u304b\u9069\u7528\u51fa\u6765\u306a\u3044\u3002\uff08\u4ed6\u306e\u5834\u5408\u306f\u5143\u306e\u30e1\u30bd\u30c3\u30c9\u306e\u7b2c\u4e00\u5f15\u6570\u306eself\u3092__call__\u306e\u4e2d\u3067\u753b\u4e00\u7684\u306a\u65b9\u6cd5\u3067\u53d6\u308a\u51fa\u305b\u306a\u3044\u3063\u307d\u3044\u3002\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>n\u56de\u306e\u547c\u3073\u51fa\u3057\u306e\u3046\u30611\u56de\u3057\u304b\u5b9f\u969b\u306e\u51e6\u7406\u3092\u884c\u308f\u306a\u3044\u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u8003\u3048\u3066\u307f\u305f\u3002<br \/>\n\uff08Zinnia\u3092\u4f7f\u3063\u3066\u624b\u66f8\u304d\u6587\u5b57\u3092\u8a8d\u8b58\u3059\u308b\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u4f5c\u3063\u3066\u305f\u3068\u304d\u306b\u3001\u30da\u30f3\u306e\u63cf\u753b\uff08\u30de\u30a6\u30b9\u306e\u30c9\u30e9\u30c3\u30b0\uff09\u30a4\u30d9\u30f3\u30c8\u304c\u7269\u51c4\u3044\u56de\u6570\u8d77\u304d\u3066\u3082\u5ea7\u6a19\u30c7\u30fc\u30bf\u304c\u5897\u5927\u3059\u308b\u3060\u3051\u3067\u7cbe\u5ea6\u306f\u3042\u307e\u308a\u4e0a\u304c\u3089\u306a\u3044\u3093\u3058\u3083\u306a\u3044\u304b\u3068\u601d\u3044\u3001\u7a0b\u826f\u304f\u51e6\u7406\u56de\u6570\u3092\u6e1b\u3089\u3059\u305f\u3081\u8003\u3048\u305f\u3002\uff09<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef negligence(n):\r\n\tu'''n\u56de\u306b1\u56de\u3057\u304b\u51e6\u7406\u3057\u306a\u3044\u30c7\u30b3\u30ec\u30fc\u30bf'''\r\n\r\n\tdef _(f):\r\n\t\tf.call_count = -1\r\n\t\tdef __(*args, **kwargs):\r\n\t\t\tf.call_count += 1\r\n\t\t\tif f.call_count % n == 0:\r\n\t\t\t\tf.call_count = 0\r\n\t\t\t\treturn f(*args, **kwargs)\r\n\t\treturn __\r\n\treturn _\r\n<\/pre>\n<p>\u4f7f\u3044\u65b9<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nclass negtest(object):\r\n\t@negligence(3)\r\n\tdef test(self, text): \r\n\t\tprint text\r\n\r\n@negligence(5)\r\ndef nttest(text):\r\n\tprint text\r\n\r\nnt = negtest()\r\nfor i in range(10):\r\n\tnt.test('test%d' % i)\r\n\r\nprint\r\n\r\nfor i in range(15):\r\n\tnttest('test%d' %i)\r\n\r\n# \u5b9f\u884c\u7d50\u679c\r\ntest0\r\ntest3\r\ntest6\r\ntest9\r\n\r\ntest0\r\ntest5\r\ntest10\r\n<\/pre>\n<p>\u6ce8\u610f\u70b9<br \/>\n\u95a2\u6570\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306bcall_count\u3068\u3044\u3046\u5c5e\u6027\u3092\u8ffd\u52a0\u3057\u3066\u308b\u306e\u3067\u30d0\u30c3\u30c6\u30a3\u30f3\u30b0\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u3002<br \/>\n\u51e6\u7406\u3057\u306a\u304b\u3063\u305f\u5834\u5408\u306e\u623b\u308a\u5024\u3068\u3057\u3066None\u304c\u8fd4\u3063\u3066\u304f\u308b\u305f\u3081\u3001\u547c\u3073\u51fa\u3057\u5074\u3067\u305d\u308c\u3092\u8003\u616e\u3057\u3066\u306a\u3044\u3068\u554f\u984c\u304c\u8d77\u304d\u308b\u304b\u3082\u3002\uff08\u623b\u308a\u5024\u3092\u4f7f\u3046\u90e8\u5206\u3067\u51e6\u7406\u3092\u7701\u304d\u305f\u304b\u3063\u305f\u3089Memoize\uff01\uff09<br \/>\n\u3068\u3044\u3046\u304b\u3001\u305d\u3082\u305d\u3082\u56fa\u5b9a\u7684\u306b\u51e6\u7406\u56de\u6570\u3092\u6e1b\u3089\u3057\u305f\u3044\u4e8b\u3063\u3066\u3042\u307e\u308a\u7121\u3044\u3088\u3046\u306aw \u7279\u306b\u307e\u3068\u3082\u306a\u30d7\u30ed\u30b0\u30e9\u30e0\u306b\u306a\u308c\u3070\u306a\u308b\u307b\u3069\u3002<\/p>\n<p>\u5931\u6557\u4f5c<br \/>\n\u547c\u3073\u51fa\u3057\u56de\u6570\u3068\u3044\u3046\u72b6\u614b\u3092\u6301\u3064\u305f\u3081\u3001\u6700\u521d\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u30af\u30e9\u30b9\u3092\u8fd4\u3059\u30c7\u30b3\u30ec\u30fc\u30bf\u3067\u5b9f\u88c5\u3057\u3066\u305f\u3051\u3069\u3001function\u306e\u5834\u5408\u3001bound method\u306e\u5834\u5408\u3001unbound method\u306e\u5834\u5408\u3001\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u5834\u5408\u306e\u3059\u3079\u3066\u3067\u753b\u4e00\u7684\u306a\u65b9\u6cd5\u3067\u6b63\u5e38\u306b\u52d5\u4f5c\u3055\u305b\u308b\u65b9\u6cd5\u304c\u5206\u304b\u3089\u305a\u65ad\u5ff5\u3002<br \/>\nsys._getframe\u3068\u304b\u4f7f\u3063\u3066\u307f\u305f\u3051\u3069\u3001\u305d\u308c\u305e\u308c\u306e\u5834\u5408\u3067\u3046\u307e\u304f\u52d5\u304f\u65b9\u6cd5\u304c\u3042\u3063\u305f\u3068\u3057\u3066\u3082\u3001\u6fc0\u3057\u304f\u5834\u5408\u5206\u3051\u304c\u5fc5\u8981\u306a\u4e88\u611f\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\ndef negligence(n):\r\n\tu'''n\u56de\u306b1\u56de\u3057\u304b\u51e6\u7406\u3057\u306a\u3044\u30c7\u30b3\u30ec\u30fc\u30bf'''\r\n\t\r\n\tclass _(object):\r\n\t\t\r\n\t\tdef __init__(self, f):\r\n\t\t\tself.__f = f\r\n\t\t\tself.__call_count = -1\r\n\t\t\r\n\t\tdef __call__(self, *args, **kwargs):\r\n\t\t\tself.__call_count += 1\r\n\t\t\tif self.__call_count % n == 0:\r\n\t\t\t\tself.__call_count = 0\r\n\t\t\t\treturn self.__f(*args, **kwargs)\r\n\treturn _\r\n<\/pre>\n<p>\u3061\u306a\u307f\u306b\u3053\u306e\u4f8b\u3060\u3068function\u306b\u3057\u304b\u9069\u7528\u51fa\u6765\u306a\u3044\u3002\uff08\u4ed6\u306e\u5834\u5408\u306f\u5143\u306e\u30e1\u30bd\u30c3\u30c9\u306e\u7b2c\u4e00\u5f15\u6570\u306eself\u3092__call__\u306e\u4e2d\u3067\u753b\u4e00\u7684\u306a\u65b9\u6cd5\u3067\u53d6\u308a\u51fa\u305b\u306a\u3044\u3063\u307d\u3044\u3002\uff09<\/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-946","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\/946","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=946"}],"version-history":[{"count":0,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/posts\/946\/revisions"}],"wp:attachment":[{"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/media?parent=946"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/categories?post=946"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/peta.okechan.net\/blog\/wp-json\/wp\/v2\/tags?post=946"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}