{"id":1159,"date":"2018-09-05T00:22:04","date_gmt":"2018-09-04T15:22:04","guid":{"rendered":"https:\/\/python-introduction.com\/?p=1159"},"modified":"2018-09-03T17:06:33","modified_gmt":"2018-09-03T08:06:33","slug":"%e3%80%90python%e3%80%91with%e6%96%87%e3%81%ae%e4%bd%bf%e3%81%84%e6%96%b9%e3%81%ab%e3%81%a4%e3%81%84%e3%81%a6as%e3%81%a8%e3%81%8b%e3%82%89%e3%82%81%e3%81%a6%e8%a7%a3%e8%aa%ac","status":"publish","type":"post","link":"https:\/\/python-introduction.com\/?p=1159","title":{"rendered":"\u3010Python\u3011with\u6587\u306e\u4f7f\u3044\u65b9\u306b\u3064\u3044\u3066as\u3068\u304b\u3089\u3081\u3066\u89e3\u8aac"},"content":{"rendered":"<p>\u3053\u306e\u8a18\u4e8b\u3067\u306fwith\u6587\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\n\u307e\u305f\u3001with\u6587\u306e\u4e2d\u306bas\u3092\u5165\u308c\u308b\u8a18\u8ff0\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3082\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n<h2>\u3010Python\u3011with\u6587\u3068as\u3092\u4f7f\u3063\u3066\u30d5\u30a1\u30a4\u30eb\u306e\u66f8\u304d\u8fbc\u307f\u3092\u3059\u308b\u65b9\u6cd5<\/h2>\n<p>\u524d\u56de\u306e\u8a18\u4e8b\u3067\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044\u305f\u308a\u8aad\u307f\u8fbc\u3093\u3060\u308a\u3059\u308b\u65b9\u6cd5\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u307e\u3057\u305f\u3002<br \/>\n\u21d2<a href=\"https:\/\/python-introduction.com\/?p=1149\" target=\"blank\">\u3010Python\u3011\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u65b9\u6cd5\u3092\u308f\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac<\/a><\/p>\n<p>\u3061\u306a\u307f\u306b\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u306e\u306bopen()\u3092\u4f7f\u3044\u307e\u3057\u305f\u3057<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u306bread()\u3001\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058\u308b\u306e\u306bclose()\u3092\u4f7f\u3044\u307e\u3057\u305f\u306d\u3002<\/p>\n<p>\u307e\u305f\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u66f8\u304d\u8fbc\u307f\u306f<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">x = open('konn.txt', 'w')<\/pre>\n<p>\u3068\u7b2c2\u5f15\u6570\u306bw\u3068\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3067\u5b9f\u73fe\u3067\u304d\u307e\u3057\u305f\u3002<\/p>\n<p>\u524d\u56de\u307e\u3067\u306e\u65b9\u6cd5\u3060\u3068<br \/>\n\u30b3\u30fc\u30c9\u306e\u8a18\u8ff0\u304c\u3084\u3084\u9577\u3063\u305f\u3089\u3057\u304f\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u305d\u3053\u3067\u3001\u4eca\u56de\u89e3\u8aac\u3059\u308bwith\u6587\u304c\u767b\u5834\u3059\u308b\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u984c1\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">#\u4f8b\u984c1\r\nx = 'Is this a flower or a dog?'\r\ny = open('doubutu.txt', 'w')\r\nz = y.write(x)\r\ny.close()\r\nprint(x)<\/pre>\n<p>\u4f8b\u984c1\u306f\u524d\u56de\u89e3\u8aac\u3057\u305fopen\u3084w\u3092\u4f7f\u3063\u3066\u30d5\u30a1\u30a4\u30eb\u306e\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3044\u307e\u3057\u305f\u3002<br \/>\n\u30b3\u30fc\u30c9\u306e\u610f\u5473\u5408\u3044\u306b\u3064\u3044\u3066\u306f\u3053\u3061\u3089\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u21d2<a href=\"https:\/\/python-introduction.com\/?p=1065\" target=\"blank\">\u3010Python\u3011\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u30fb\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307f\u3059\u308b\u65b9\u6cd5<\/a><\/p>\n<p>\u5b9f\u884c\u3059\u308b\u3068<br \/>\nIs this a flower or a dog?<\/p>\n<p>\u3068\u8868\u793a\u3055\u308c\u3064\u3064\u3001<br \/>\n<img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/python-introduction.com\/wp-content\/uploads\/2018\/09\/doubutufiru831.jpg\" alt=\"doubutufairu\" width=\"228\" height=\"69\" class=\"alignnone size-full wp-image-1163\" \/><\/p>\n<p>doubutu.txt\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u304c\u4f5c\u6210\u3055\u308c\u307e\u3059\u3002<br \/>\n\u305d\u3057\u3066doubutu.txt\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u3068<br \/>\n<img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/python-introduction.com\/wp-content\/uploads\/2018\/09\/openda903.jpg\" alt=\"with\u6587\" width=\"279\" height=\"135\" class=\"alignnone size-full wp-image-1164\" \/><\/p>\n<p>Is this a flower or a dog?<br \/>\n\u3068\u3044\u3046\u6587\u5b57\u5217\u304c\u66f8\u304d\u8fbc\u307e\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u3001\u4f8b\u984c1\u306e\u3088\u3046\u306a\u8a18\u8ff0\u65b9\u6cd5\u3067\u306a\u304f\u3066\u3082<br \/>\nwith\u6587\u3068as\u3092\u4f7f\u3046\u3053\u3068\u3067<br \/>\n\u3088\u308a\u77ed\u3044\u8a18\u8ff0\u3067\u76ee\u7684\u3092\u9054\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3093\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u984c2\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">#\u4f8b\u984c2\r\nx = 'Is this a flower or a dog?'\r\nwith open('doubutu.txt','w') as y:\r\n    y.write(x)\r\nprint(x)<\/pre>\n<p>\u4f8b\u984c2\u306f\u4f8b\u984c1\u3068\u307e\u3063\u305f\u304f\u540c\u3058\u7d50\u679c\u304c\u5f97\u3089\u308c\u307e\u3059\u3002<br \/>\n\u4f8b\u984c2\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u306d\u3002<\/p>\n<p>\u307e\u305a\u5909\u6570x\u306bIs this a flower or a dog?\u3068\u3044\u3046\u6587\u5b57\u5217\u3092\u4ee3\u5165\u3057\u307e\u3059\u3002<\/p>\n<p>\u305d\u308c\u304b\u3089<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">with open('doubutu.txt','w') as y:<\/pre>\n<p>\u5148\u307b\u3069\u306eIs this a flower or a dog?\u3068\u3044\u3046\u6587\u5b57\u5217\u3092<br \/>\ndoubutu.txt\u3068\u3044\u3046\u30d5\u30a1\u30a4\u30eb\u306b\u66f8\u304d\u8fbc\u307f\u307e\u3059\u3002<\/p>\n<p>\u305d\u306e\u3068\u304d\u306bwith\u6587\u3092\u4f7f\u3044\u307e\u3059\u3002<br \/>\n\u6700\u521d\u306bwith\u3068\u8a18\u8ff0\u3057\u3001\u305d\u306e\u3042\u3068\u306bopen\u95a2\u6570\u3092\u4f7f\u3044\u307e\u3059\u3002<br \/>\nopen\u95a2\u6570\u306e\u5f8c\u306b\u3001as\u3068\u66f8\u3044\u3066\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u540d\u3092\u66f8\u304d\u3001\u300e:\uff08\u30b3\u30ed\u30f3\uff09\u300f<br \/>\n\u3092\u5165\u308c\u307e\u3057\u3087\u3046\u3002<\/p>\n<p>\u305d\u308c\u304b\u3089<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">    y.write(x)<\/pre>\n<p>\u30a4\u30f3\u30c7\u30f3\u30c8\uff08\u7a7a\u767d\u3092\u958b\u3051\u308b\u3053\u3068\uff09\u3092\u3068\u3063\u3066\u3001write\u95a2\u6570\u3092\u4f7f\u3063\u3066<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u66f8\u304d\u8fbc\u307f\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u3093\u306a\u611f\u3058\u3067with\u6587\u3068as\u3092\u4f7f\u3046\u3053\u3068\u3067<br \/>\nclose\u95a2\u6570\u3092\u4f7f\u7528\u3059\u308b\u5fc5\u8981\u304c\u306a\u304f\u306a\u308a\u3001<br \/>\n\u4f8b\u984c1\u3088\u308a\u3082\u77ed\u3044\u30b3\u30fc\u30c9\u3067\u76ee\u7684\u3092\u9054\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308b\u3093\u3067\u3059\u3002<\/p>\n<p>\u4f8b\u984c1\u3068\u6bd4\u3079\u30661\u884c\u5c11\u306a\u3044\u3060\u3051\u3067\u3059\u304c<br \/>\n\u305d\u308c\u3067\u3082\u3001\u5927\u898f\u6a21\u306a\u30d7\u30ed\u30b0\u30e9\u30df\u30f3\u30b0\u306a\u3089\u4f55\u5341\u884c\u3001<br \/>\n\u4f55\u767e\u884c\u306e\u5dee\u306b\u306a\u3063\u3066\u304f\u308b\u3053\u3068\u3082\u3042\u308b\u306e\u3067\u3001<br \/>\n\u610f\u5473\u306e\u3042\u308b\u3053\u3068\u3067\u3059\u3002<\/p>\n<h2>\u3010Python\u3011with\u6587\u3068as\u3092\u4f7f\u3063\u3066\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u3059\u308b\u65b9\u6cd5<\/h2>\n<p>\u4f8b\u984c3\u3092\u3054\u89a7\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">#\u4f8b\u984c3\r\nx = open('doubutu.txt', 'r')\r\ny = x.read()\r\nx.close()\r\nprint(y)<\/pre>\n<p>\u4f8b\u984c3\u306f\u524d\u56de\u306e\u8a18\u4e8b\u3067\u89e3\u8aac\u3057\u305f\u65b9\u6cd5\u3067<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u884c\u3044\u307e\u3057\u305f\u3002<br \/>\n\u21d2<a href=\"https:\/\/python-introduction.com\/?p=1149\" target=\"blank\">\u3010Python\u3011\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u65b9\u6cd5\u3092\u308f\u304b\u308a\u3084\u3059\u304f\u89e3\u8aac<\/a><\/p>\n<p>\u5b9f\u884c\u3059\u308b\u3068<br \/>\nIs this a flower or a dog?<br \/>\n\u3068\u8868\u793a\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u984c3\u3092with\u6587\u3067\u66f8\u304d\u63db\u3048\u3066\u307f\u307e\u3057\u3087\u3046\u3002<br \/>\n\u4f8b\u984c4\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">#\u4f8b\u984c4 with\u6587\u3092\u4f7f\u3063\u305f\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\r\nwith open('doubutu.txt','r') as y:\r\n    print(y.read())<\/pre>\n<p>\u304b\u306a\u308a\u3059\u3063\u304d\u308a\u3057\u307e\u3057\u305f\u306d\u3002<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">with open('doubutu.txt','r') as y:<\/pre>\n<p>with\u306e\u5f8c\u306b\u3001open()\u95a2\u6570\u3092\u4f7f\u3063\u3066doubutu.txt\u3092\u958b\u304d\u3001\u7b2c2\u5f15\u6570\u3067r\u3092\u4f7f\u3046\u3053\u3068\u3067<br \/>\n\u30d5\u30a1\u30a4\u30eb\u5185\u5bb9\u3092\u8aad\u307f\u8fbc\u3093\u3067\u3044\u308b\u308f\u3051\u3067\u3059\u3002<\/p>\n<p>\u305d\u308c\u304b\u3089<\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">    print(y.read())<\/pre>\n<p>\u3068\u3059\u308b\u3053\u3068\u3067\u3001doubutu.txt\u3092\u8aad\u307f\u8fbc\u307f<br \/>\n\u8868\u793a\u3055\u305b\u3066\u3044\u308b\u308f\u3051\u3067\u3059\u306d\u3002<\/p>\n<p>with\u6587\u3092\u4f7f\u3046\u3053\u3068\u3067<br \/>\nclose\u95a2\u6570\u3092\u4f7f\u308f\u306a\u304f\u3066\u3082\u30d5\u30a1\u30a4\u30eb\u3092\u9589\u3058\u308b\u3053\u3068\u304c\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u3057\u305f\u304c\u3063\u3066\u3001<span class=\"yellowbg\">with\u6587\u3092\u4f7f\u3046\u3068\u3044\u3046\u3053\u3068\u306f<br \/>\n\u3088\u308a\u3001\u77ed\u3044\u8a18\u8ff0\u3067\u76ee\u7684\u3092\u9054\u6210\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3057<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u9589\u3058\u5fd8\u308c\u3092\u9632\u6b62\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u308b<\/span>\u308f\u3051\u3067\u3059\u306d\u3002<\/p>\n<p>\u305d\u3046\u3044\u3063\u305f\u610f\u5473\u3067\u306f<br \/>\n\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d\u306b\u95a2\u3057\u3066<br \/>\nwith\u6587\u306f\u304b\u306a\u308a\u4f7f\u3044\u52dd\u624b\u304c\u3088\u3044\u3082\u306e\u3060\u3068\u3044\u3048\u307e\u3059\u306d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u3053\u306e\u8a18\u4e8b\u3067\u306fwith\u6587\u306b\u3064\u3044\u3066\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002 \u307e\u305f\u3001with\u6587\u306e\u4e2d\u306bas\u3092\u5165\u308c\u308b\u8a18\u8ff0\u65b9\u6cd5\u306b\u3064\u3044\u3066\u3082\u89e3\u8aac\u3057\u3066\u3044\u304d\u307e\u3059\u3002 \u3010Python\u3011with\u6587\u3068as\u3092\u4f7f\u3063\u3066\u30d5\u30a1\u30a4\u30eb\u306e\u66f8\u304d\u8fbc\u307f\u3092\u3059\u308b\u65b9\u6cd5 \u524d\u56de\u306e\u8a18\u4e8b\u3067\u306f\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u3044 [&hellip;]","protected":false},"author":1,"featured_media":1038,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16,117],"tags":[119,3,118],"_links":{"self":[{"href":"https:\/\/python-introduction.com\/index.php?rest_route=\/wp\/v2\/posts\/1159"}],"collection":[{"href":"https:\/\/python-introduction.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/python-introduction.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/python-introduction.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/python-introduction.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1159"}],"version-history":[{"count":8,"href":"https:\/\/python-introduction.com\/index.php?rest_route=\/wp\/v2\/posts\/1159\/revisions"}],"predecessor-version":[{"id":1169,"href":"https:\/\/python-introduction.com\/index.php?rest_route=\/wp\/v2\/posts\/1159\/revisions\/1169"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/python-introduction.com\/index.php?rest_route=\/wp\/v2\/media\/1038"}],"wp:attachment":[{"href":"https:\/\/python-introduction.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/python-introduction.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1159"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/python-introduction.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}