{"id":3612,"date":"2026-10-27T10:59:05","date_gmt":"2026-10-27T01:59:05","guid":{"rendered":"https:\/\/qol-kk.com\/wp2\/?p=3612"},"modified":"2026-10-27T10:59:05","modified_gmt":"2026-10-27T01:59:05","slug":"20261027-plan072","status":"publish","type":"post","link":"https:\/\/qol-kk.com\/wp2\/blog\/2026\/10\/27\/20261027-plan072\/","title":{"rendered":"Python \u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\uff08with\u6587\uff09\u3092\u81ea\u4f5c\u3059\u308b"},"content":{"rendered":"<p>Python \u3067\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u3068\u304d\u306b\u66f8\u304f <code>with open(...) as f:<\/code> \u306e <code>with<\/code> \u6587\u3002\u3053\u306e\u88cf\u5074\u3067\u52d5\u3044\u3066\u3044\u308b\u306e\u304c\u300c\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u300d\u3067\u3059\u3002\u672c\u8a18\u4e8b\u3067\u306f\u3001\u305d\u306e\u4ed5\u7d44\u307f\u3092\u7406\u89e3\u3057\u3001\u30af\u30e9\u30b9\u3068 <code>contextlib<\/code> \u306e2\u901a\u308a\u3067\u81ea\u4f5c\u3059\u308b\u65b9\u6cd5\u3092\u5165\u9580\u8005\u5411\u3051\u306b\u89e3\u8aac\u3057\u307e\u3059\u3002<\/p>\n<p>\u5bfe\u8c61\u8aad\u8005\u306f\u300c<code>with open()<\/code> \u306f\u4f7f\u3048\u308b\u304c\u3001\u81ea\u5206\u3067 <code>with<\/code> \u306b\u5bfe\u5fdc\u3057\u305f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u3063\u305f\u3053\u3068\u306f\u306a\u3044\u300d\u3068\u3044\u3046\u65b9\u3067\u3059\u3002\u74b0\u5883\u306f Python 3.8 \u4ee5\u4e0a\uff08\u30b3\u30fc\u30c9\u306f 3.12 \u3067\u78ba\u8a8d\uff09\u3001\u8ffd\u52a0\u30e9\u30a4\u30d6\u30e9\u30ea\u306f\u4e0d\u8981\u3067\u3059\u3002<\/p>\n<h2>\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u3068\u306f\u4f55\u304b<\/h2>\n<p>\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u3068\u306f\u3001<code>with<\/code> \u6587\u3067\u4f7f\u3048\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u3053\u3068\u3067\u3059\u3002\u3084\u3063\u3066\u3044\u308b\u3053\u3068\u306f2\u3064\u3060\u3051\u3067\u3059\u3002<\/p>\n<ol>\n<li>\u30d6\u30ed\u30c3\u30af\u306b\u5165\u308b\u3068\u304d\u306b\u300c\u524d\u51e6\u7406\uff08\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\uff09\u300d\u3092\u3059\u308b<\/li>\n<li>\u30d6\u30ed\u30c3\u30af\u3092\u629c\u3051\u308b\u3068\u304d\u306b\u300c\u5f8c\u51e6\u7406\uff08\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\uff09\u300d\u3092\u3059\u308b<\/li>\n<\/ol>\n<p>\u91cd\u8981\u306a\u306e\u306f\u3001<strong>\u30d6\u30ed\u30c3\u30af\u5185\u3067\u4f8b\u5916\u304c\u767a\u751f\u3057\u3066\u3082\u5f8c\u51e6\u7406\u304c\u5fc5\u305a\u5b9f\u884c\u3055\u308c\u308b<\/strong>\u3068\u3044\u3046\u70b9\u3067\u3059\u3002<\/p>\n<p>\u30d5\u30a1\u30a4\u30eb\u3092\u4f8b\u306b\u8003\u3048\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">f = open(\"data.txt\")\ntry:\n    data = f.read()\nfinally:\n    f.close()  # \u4f8b\u5916\u304c\u8d77\u304d\u3066\u3082\u5fc5\u305a\u9589\u3058\u308b<\/pre>\n<p>\u3053\u306e <code>try \/ finally<\/code> \u3092\u6bce\u56de\u66f8\u304f\u306e\u306f\u9762\u5012\u3067\u3001<code>close()<\/code> \u306e\u66f8\u304d\u5fd8\u308c\u3082\u8d77\u3053\u308a\u307e\u3059\u3002<code>with<\/code> \u6587\u306f\u3053\u306e\u5b9a\u578b\u3092\u96a0\u853d\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">with open(\"data.txt\") as f:\n    data = f.read()\n# \u30d6\u30ed\u30c3\u30af\u3092\u629c\u3051\u305f\u6642\u70b9\u3067 f \u306f\u5fc5\u305a\u9589\u3058\u3089\u308c\u3066\u3044\u308b<\/pre>\n<p>\u3053\u306e\u300c\u5fc5\u305a\u5f8c\u51e6\u7406\u3059\u308b\u300d\u3092\u30e6\u30fc\u30b6\u30fc\u5b9a\u7fa9\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3082\u5b9f\u73fe\u3067\u304d\u308b\u306e\u304c\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u3067\u3059\u3002<\/p>\n<h2>\u4ed5\u7d44\u307f\uff1a<code>__enter__<\/code> \u3068 <code>__exit__<\/code><\/h2>\n<p><code>with<\/code> \u6587\u306b\u5bfe\u5fdc\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306f\u3001\u6b21\u306e2\u3064\u306e\u7279\u6b8a\u30e1\u30bd\u30c3\u30c9\u3092\u6301\u3061\u307e\u3059\u3002<\/p>\n<ul>\n<li><code>__enter__(self)<\/code> \u2014 \u30d6\u30ed\u30c3\u30af\u306b\u5165\u308b\u3068\u304d\u306b\u547c\u3070\u308c\u308b\u3002\u623b\u308a\u5024\u304c <code>as<\/code> \u306e\u5909\u6570\u306b\u5165\u308b<\/li>\n<li><code>__exit__(self, exc_type, exc_value, traceback)<\/code> \u2014 \u30d6\u30ed\u30c3\u30af\u3092\u629c\u3051\u308b\u3068\u304d\u306b\u547c\u3070\u308c\u308b\u3002\u5f8c\u51e6\u7406\u3092\u66f8\u304f<\/li>\n<\/ul>\n<p><code>with cm as x:<\/code> \u306f\u3001\u304a\u304a\u3088\u305d\u6b21\u3068\u7b49\u4fa1\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">x = cm.__enter__()\ntry:\n    ...  # with \u30d6\u30ed\u30c3\u30af\u306e\u4e2d\u8eab\nfinally:\n    cm.__exit__(\u4f8b\u5916\u306e\u578b, \u4f8b\u5916\u306e\u5024, \u30c8\u30ec\u30fc\u30b9\u30d0\u30c3\u30af)<\/pre>\n<p>\u4f8b\u5916\u304c\u8d77\u304d\u306a\u304b\u3063\u305f\u5834\u5408\u3001<code>__exit__<\/code> \u306e3\u5f15\u6570\u306f\u3059\u3079\u3066 <code>None<\/code> \u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<h2>\u65b9\u6cd51\uff1a\u30af\u30e9\u30b9\u3067\u81ea\u4f5c\u3059\u308b<\/h2>\n<p>\u4e00\u756a\u57fa\u672c\u7684\u306a\u65b9\u6cd5\u304c\u3001<code>__enter__<\/code> \/ <code>__exit__<\/code> \u3092\u6301\u3064\u30af\u30e9\u30b9\u3092\u5b9a\u7fa9\u3059\u308b\u3053\u3068\u3067\u3059\u3002\u51e6\u7406\u6642\u9593\u3092\u8a08\u6e2c\u3059\u308b\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u3092\u4f5c\u3063\u3066\u307f\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">import time\n\n\nclass Timer:\n    def __init__(self, label=\"\u51e6\u7406\"):\n        self.label = label\n\n    def __enter__(self):\n        self.start = time.perf_counter()\n        return self  # as \u3067\u53d7\u3051\u53d6\u308b\u5024\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        elapsed = time.perf_counter() - self.start\n        print(f\"{self.label}: {elapsed:.4f} \u79d2\")\n\n\nwith Timer(\"\u96c6\u8a08\u51e6\u7406\"):\n    total = sum(range(10_000_000))\n# \u51fa\u529b\u4f8b: \u96c6\u8a08\u51e6\u7406: 0.1532 \u79d2<\/pre>\n<p><code>__enter__<\/code> \u304c <code>return self<\/code> \u3057\u3066\u3044\u308b\u306e\u3067\u3001<code>as t:<\/code> \u3068\u66f8\u3051\u3070 <code>Timer<\/code> \u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u81ea\u4f53\u3092\u53d7\u3051\u53d6\u308c\u307e\u3059\u3002<\/p>\n<h3>\u4f8b\u5916\u304c\u8d77\u304d\u3066\u3082\u5f8c\u51e6\u7406\u306f\u8d70\u308b<\/h3>\n<p>\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u306e\u672c\u8cea\u306f\u300c\u4f8b\u5916\u304c\u8d77\u304d\u3066\u3082\u5f8c\u51e6\u7406\u304c\u8d70\u308b\u300d\u3053\u3068\u3067\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class Resource:\n    def __enter__(self):\n        print(\"\u2192 \u63a5\u7d9a\u3092\u958b\u304f\")\n        return self\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        print(\"\u2192 \u63a5\u7d9a\u3092\u9589\u3058\u308b\")\n\n\nwith Resource():\n    print(\"\u51e6\u7406\u4e2d\")\n    raise ValueError(\"\u60f3\u5b9a\u5916\u306e\u30a8\u30e9\u30fc\")<\/pre>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u6b21\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">\u2192 \u63a5\u7d9a\u3092\u958b\u304f\n\u51e6\u7406\u4e2d\n\u2192 \u63a5\u7d9a\u3092\u9589\u3058\u308b\nTraceback (most recent call last):\n  ...\nValueError: \u60f3\u5b9a\u5916\u306e\u30a8\u30e9\u30fc<\/pre>\n<p><code>raise<\/code> \u3067\u4e2d\u65ad\u3055\u308c\u3066\u3082\u300c\u63a5\u7d9a\u3092\u9589\u3058\u308b\u300d\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u307e\u3059\u3002\u3053\u308c\u304c DB \u63a5\u7d9a\u30fb\u30d5\u30a1\u30a4\u30eb\u30fb\u30ed\u30c3\u30af\u30fb\u4e00\u6642\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u306a\u3069\u300c\u5fc5\u305a\u89e3\u653e\u3057\u305f\u3044\u30ea\u30bd\u30fc\u30b9\u300d\u306e\u7ba1\u7406\u306b\u5411\u304f\u7406\u7531\u3067\u3059\u3002<\/p>\n<h3><code>__exit__<\/code> \u306e\u623b\u308a\u5024\u3067\u4f8b\u5916\u3092\u6291\u5236\u3059\u308b<\/h3>\n<p><code>__exit__<\/code> \u304c <strong><code>True<\/code> \u3092\u8fd4\u3059\u3068\u3001\u30d6\u30ed\u30c3\u30af\u5185\u3067\u8d77\u304d\u305f\u4f8b\u5916\u3092\u6291\u5236<\/strong>\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">class SuppressValueError:\n    def __enter__(self):\n        return self\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        return exc_type is ValueError  # ValueError \u3060\u3051\u63e1\u308a\u3064\u3076\u3059\n\n\nwith SuppressValueError():\n    raise ValueError(\"\u3053\u308c\u306f\u7121\u8996\u3055\u308c\u308b\")\n\nprint(\"\u3053\u3053\u307e\u3067\u5230\u9054\u3059\u308b\")<\/pre>\n<p>\u4fbf\u5229\u3067\u3059\u304c\u3001\u4f8b\u5916\u3092\u5b89\u6613\u306b\u63e1\u308a\u3064\u3076\u3059\u3068\u30d0\u30b0\u306e\u6e29\u5e8a\u306b\u306a\u308a\u307e\u3059\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\uff08<code>None<\/code> \u3092\u8fd4\u3059\uff09\u3067\u306f\u4f8b\u5916\u306f\u305d\u306e\u307e\u307e\u4f1d\u64ad\u3057\u307e\u3059\u3002<\/p>\n<h2>\u65b9\u6cd52\uff1a<code>contextlib.contextmanager<\/code> \u3067\u81ea\u4f5c\u3059\u308b<\/h2>\n<p>\u30af\u30e9\u30b9\u304c\u5927\u3052\u3055\u306b\u611f\u3058\u308b\u5834\u5408\u3001<code>contextlib.contextmanager<\/code> \u30c7\u30b3\u30ec\u30fc\u30bf\u3092\u4f7f\u3046\u3068<strong>\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u95a2\u65701\u3064<\/strong>\u3067\u66f8\u3051\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">import time\nfrom contextlib import contextmanager\n\n\n@contextmanager\ndef timer(label=\"\u51e6\u7406\"):\n    start = time.perf_counter()\n    try:\n        yield  # \u3053\u3053\u3067 with \u30d6\u30ed\u30c3\u30af\u306b\u5236\u5fa1\u304c\u6e21\u308b\n    finally:\n        elapsed = time.perf_counter() - start\n        print(f\"{label}: {elapsed:.4f} \u79d2\")\n\n\nwith timer(\"\u96c6\u8a08\u51e6\u7406\"):\n    total = sum(range(10_000_000))<\/pre>\n<p>\u30dd\u30a4\u30f3\u30c8\u306f <code>yield<\/code> \u3067\u3059\u3002<\/p>\n<ul>\n<li><code>yield<\/code> \u306e <strong>\u524d<\/strong> \u304c <code>__enter__<\/code> \u76f8\u5f53\uff08\u30bb\u30c3\u30c8\u30a2\u30c3\u30d7\uff09<\/li>\n<li><code>yield<\/code> \u3067 <code>with<\/code> \u30d6\u30ed\u30c3\u30af\u306b\u5236\u5fa1\u304c\u6e21\u308b<\/li>\n<li><code>yield<\/code> \u306e <strong>\u5f8c<\/strong>\uff08<code>finally<\/code>\uff09\u304c <code>__exit__<\/code> \u76f8\u5f53\uff08\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\uff09<\/li>\n<\/ul>\n<p>\u5024\u3092 <code>as<\/code> \u3067\u6e21\u3057\u305f\u3044\u5834\u5408\u306f <code>yield value<\/code> \u3068\u66f8\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"lang:default decode:true\">@contextmanager\ndef opened(path):\n    f = open(path)\n    try:\n        yield f  # as f: \u3067\u3053\u306e\u5024\u3092\u53d7\u3051\u53d6\u308b\n    finally:\n        f.close()\n\n\nwith opened(\"data.txt\") as f:\n    print(f.read())<\/pre>\n<p>\u4f8b\u5916\u306b\u5099\u3048\u3066\u3001<code>yield<\/code> \u306f\u5fc5\u305a <code>try \/ finally<\/code> \u3067\u56f2\u3080\u306e\u304c\u9244\u5247\u3067\u3059\u3002\u56f2\u307e\u306a\u3044\u3068\u3001\u30d6\u30ed\u30c3\u30af\u5185\u3067\u4f8b\u5916\u304c\u8d77\u304d\u305f\u3068\u304d\u306b\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u304c\u8d70\u308a\u307e\u305b\u3093\u3002<\/p>\n<h2>\u30af\u30e9\u30b9\u7248\u3068\u30c7\u30b3\u30ec\u30fc\u30bf\u7248\u306e\u4f7f\u3044\u5206\u3051<\/h2>\n<table>\n<thead>\n<tr>\n<th>\u89b3\u70b9<\/th>\n<th>\u30af\u30e9\u30b9\u7248<\/th>\n<th><code>@contextmanager<\/code> \u7248<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u8a18\u8ff0\u91cf<\/td>\n<td>\u591a\u3081<\/td>\n<td>\u5c11\u306a\u3044<\/td>\n<\/tr>\n<tr>\n<td>\u72b6\u614b\u3092\u8907\u6570\u30e1\u30bd\u30c3\u30c9\u3067\u5171\u6709<\/td>\n<td>\u3057\u3084\u3059\u3044<\/td>\n<td>\u3057\u306b\u304f\u3044<\/td>\n<\/tr>\n<tr>\n<td>\u518d\u5229\u7528\uff08\u8907\u6570\u56de with \u3059\u308b\uff09<\/td>\n<td>\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u6b21\u7b2c\u3067\u53ef<\/td>\n<td>\u539f\u52471\u56de<\/td>\n<\/tr>\n<tr>\n<td>\u5358\u7d14\u306a\u524d\u5f8c\u51e6\u7406\u306e\u8aad\u307f\u3084\u3059\u3055<\/td>\n<td>\u3084\u3084\u5197\u9577<\/td>\n<td>\u76f4\u611f\u7684<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<ul>\n<li>\u5358\u7d14\u306a\u300c\u524d\u51e6\u7406 \u2192 yield \u2192 \u5f8c\u51e6\u7406\u300d\u306a\u3089 <code>@contextmanager<\/code><\/li>\n<li>\u72b6\u614b\u3084\u30e1\u30bd\u30c3\u30c9\u3092\u6301\u305f\u305b\u305f\u3044\u3001\u4f7f\u3044\u56de\u3057\u305f\u3044\u306a\u3089\u30af\u30e9\u30b9<\/li>\n<\/ul>\n<h2>\u6ce8\u610f\u70b9<\/h2>\n<ul>\n<li><code>@contextmanager<\/code> \u7248\u3067 <code>yield<\/code> \u3092 <code>try \/ finally<\/code> \u3067\u56f2\u307e\u306a\u3044\u3068\u3001\u4f8b\u5916\u6642\u306b\u30af\u30ea\u30fc\u30f3\u30a2\u30c3\u30d7\u304c\u8d70\u308a\u307e\u305b\u3093<\/li>\n<li><code>__exit__<\/code> \/ <code>finally<\/code> \u5185\u3067\u3055\u3089\u306b\u4f8b\u5916\u3092\u6295\u3052\u308b\u3068\u3001\u5143\u306e\u4f8b\u5916\u304c\u96a0\u308c\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059<\/li>\n<li>\u30b8\u30a7\u30cd\u30ec\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u306f\u8907\u6570\u56de <code>with<\/code> \u3067\u4f7f\u3044\u56de\u305b\u307e\u305b\u3093<\/li>\n<li>\u52d5\u7684\u306a\u500b\u6570\u306e\u30ea\u30bd\u30fc\u30b9\u3092\u7ba1\u7406\u3057\u305f\u3044\u5834\u5408\u306f <code>contextlib.ExitStack<\/code> \u304c\u4fbf\u5229\u3067\u3059<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">from contextlib import ExitStack\n\npaths = [\"a.txt\", \"b.txt\", \"c.txt\"]\nwith ExitStack() as stack:\n    files = [stack.enter_context(open(p)) for p in paths]\n    # \u30d6\u30ed\u30c3\u30af\u3092\u629c\u3051\u308c\u3070\u5168\u30d5\u30a1\u30a4\u30eb\u304c\u9589\u3058\u3089\u308c\u308b<\/pre>\n<h2>\u307e\u3068\u3081<\/h2>\n<ul>\n<li><code>with<\/code> \u6587\u306e\u88cf\u5074\u306f\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\uff08<code>__enter__<\/code> \/ <code>__exit__<\/code>\uff09<\/li>\n<li>\u672c\u8cea\u306f\u300c\u4f8b\u5916\u304c\u8d77\u304d\u3066\u3082\u5f8c\u51e6\u7406\u3092\u5fc5\u305a\u5b9f\u884c\u3059\u308b\u300d\u3053\u3068<\/li>\n<li>\u4f5c\u308a\u65b9\u306f2\u901a\u308a\uff1a\u30af\u30e9\u30b9\u5b9a\u7fa9\u3001\u307e\u305f\u306f <code>@contextmanager<\/code> + \u30b8\u30a7\u30cd\u30ec\u30fc\u30bf<\/li>\n<li>\u5358\u7d14\u306a\u524d\u5f8c\u51e6\u7406\u306f\u30c7\u30b3\u30ec\u30fc\u30bf\u7248\u3001\u72b6\u614b\u3092\u6301\u305f\u305b\u305f\u3044\u306a\u3089\u30af\u30e9\u30b9\u7248<\/li>\n<\/ul>\n<p>\u300c<code>try \/ finally<\/code> \u3092\u6bce\u56de\u66f8\u3044\u3066\u3044\u308b\u300d\u30b3\u30fc\u30c9\u3092\u898b\u3064\u3051\u305f\u3089\u3001\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u306b\u5207\u308a\u51fa\u305b\u306a\u3044\u304b\u691c\u8a0e\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002\u610f\u56f3\u304c\u660e\u78ba\u306b\u306a\u308a\u3001\u89e3\u653e\u6f0f\u308c\u3082\u9632\u3052\u307e\u3059\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python \u3067\u30d5\u30a1\u30a4\u30eb\u3092\u6271\u3046\u3068\u304d\u306b\u66f8\u304f with open(...) as f: \u306e with \u6587\u3002\u3053\u306e\u88cf\u5074\u3067\u52d5\u3044\u3066\u3044\u308b\u306e\u304c\u300c\u30b3\u30f3\u30c6\u30ad\u30b9\u30c8\u30de\u30cd\u30fc\u30b8\u30e3\u300d\u3067\u3059\u3002\u672c\u8a18\u4e8b\u3067\u306f\u3001\u305d\u306e\u4ed5\u7d44\u307f\u3092\u7406\u89e3\u3057\u3001\u30af\u30e9\u30b9\u3068 contextlib \u306e2\u901a\u308a\u3067\u81ea\u4f5c\u3059\u308b\u2026<\/p>\n","protected":false},"author":1,"featured_media":3611,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"sns_share_botton_hide":"","vkExUnit_sns_title":"","_vk_print_noindex":"","sitemap_hide":"","_veu_custom_css":"","veu_display_promotion_alert":"","vkexunit_cta_each_option":"","_lightning_design_setting":[],"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[38],"tags":[147,750],"class_list":["post-3612","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python-memorandum","tag-python","tag-750"],"veu_head_title_object":{"title":"","add_site_title":""},"jetpack_publicize_connections":[],"jetpack-related-posts":[],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/qol-kk.com\/wp2\/wp-content\/uploads\/2026\/10\/20261027-plan072-thumbnail.jpg","_links":{"self":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/3612","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/comments?post=3612"}],"version-history":[{"count":1,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/3612\/revisions"}],"predecessor-version":[{"id":3614,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/posts\/3612\/revisions\/3614"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media\/3611"}],"wp:attachment":[{"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/media?parent=3612"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/categories?post=3612"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qol-kk.com\/wp2\/wp-json\/wp\/v2\/tags?post=3612"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}