{"id":6698,"date":"2019-05-12T06:30:58","date_gmt":"2019-05-11T21:30:58","guid":{"rendered":"http:\/\/www.stuffy.site\/wordpress\/?p=6698"},"modified":"2019-05-12T12:21:06","modified_gmt":"2019-05-12T03:21:06","slug":"open-method-in-python","status":"publish","type":"post","link":"https:\/\/www.stuffy.site\/wordpress\/?p=6698","title":{"rendered":"open\u30e1\u30bd\u30c3\u30c9(Python)"},"content":{"rendered":"<p>\u5916\u90e8\u306e.txt \u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080open \u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u8abf\u3079\u305f\u306e\u3067\u30e1\u30e2\u3002<\/p>\n<p><a href=\"https:\/\/www.robotech-note.com\/entry\/2016\/10\/01\/180840\" target=\"_blank\" rel=\"noopener\">python\u3067list\u3092\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3057\u3001\u8aad\u307f\u8fbc\u3080\u65b9\u6cd5(numpy\u3082\u540c\u69d8\uff01)<\/a><\/p>\n<p>Titles.txt<\/p>\n<pre>Stand Still - Wave Racer Remix\r\nSlumber Party\r\nMilky Way Stars (feat. TR)\r\nAt The End Of The Night<\/pre>\n<p>\u4e0a\u8a18\u306e\u3088\u3046\u306a\u7d20\u306e\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u30ea\u30b9\u30c8\u306b\u8aad\u307f\u8fbc\u307f\u305f\u3044\u3068\u3057\u3066\u3002<\/p>\n<p>open(&#8216;\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9&#8217;, &#8216;\u30e2\u30fc\u30c9&#8217;, &lt;option&gt;[encoding=&#8217;utf-8&#8242;])<\/p>\n<table>\n<tbody>\n<tr>\n<td>\u30d5\u30a1\u30a4\u30eb\u30d1\u30b9<\/td>\n<td>&#8216;filepath\/filename&#8217;<\/td>\n<td>\u30b9\u30af\u30ea\u30d7\u30c8\u304b\u3089\u306e\u76f8\u5bfe\u53c2\u7167<\/td>\n<\/tr>\n<tr>\n<td rowspan=\"7\">\u30e2\u30fc\u30c9<\/td>\n<td>r<\/td>\n<td>\u8aad\u307f\u8fbc\u307f\u7528<\/td>\n<\/tr>\n<tr>\n<td>w<\/td>\n<td>\u66f8\u304d\u8fbc\u307f\u7528<\/td>\n<\/tr>\n<tr>\n<td>a<\/td>\n<td>\u8ffd\u52a0\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>r+<\/td>\n<td>\u8aad\u307f\u8fbc\u307f\u3068\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>w+<\/td>\n<td>\u8aad\u307f\u8fbc\u307f\u3068\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>a+<\/td>\n<td>\u8aad\u307f\u8fbc\u307f\u3068\u66f8\u304d\u8fbc\u307f<\/td>\n<\/tr>\n<tr>\n<td>b<\/td>\n<td>\u30d0\u30a4\u30ca\u30ea\u30e2\u30fc\u30c9<\/td>\n<\/tr>\n<tr>\n<td>option<\/td>\n<td>encoding<\/td>\n<td>utf-8, cp932(SJIS)\u306a\u3069<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>open_file.py<\/p>\n<pre>Titles = []\r\nf = open('Titles.txt', 'r')  \r\nfor x in f: \r\n    Titles.append(x.rstrip(\"\\n\")) \r\nfor title in Titles: \r\n    print(title) \r\nf.close()<\/pre>\n<p>Titles.txt \u3092\u8aad\u307f\u8fbc\u307f\u30e2\u30fc\u30c9&#8217;r&#8217; \u3067\u30d5\u30a1\u30a4\u30eb\u30aa\u30fc\u30d7\u30f3\u3057\u3066\u3001\u30ea\u30b9\u30c8\u306b\u4e00\u884c\u3065\u3064\u8ffd\u52a0\u3057\u3066\u3044\u304d\u307e\u3059\u3002<br \/>\nfor \u30eb\u30fc\u30d7\u30922\u56de\u5efb\u3059\u306e\u304c\u30b9\u30de\u30fc\u30c8\u3067\u306f\u306a\u3044\u3067\u3059\u304c\u30ea\u30b9\u30c8\u306e\u5185\u5bb9\u3092\u30d7\u30ea\u30f3\u30c8\u30a2\u30a6\u30c8\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre>f = open('Titles.txt', 'r') \r\n\u30fb \r\n\u30fb \r\n\u30fb \r\nf.close()\r\n<\/pre>\n<p>\u3068\u3059\u308b\u3068\u3053\u308d\u3092\u3001close\u5fd8\u308c\u3092\u9632\u3050\u610f\u5473\u3082\u3042\u3063\u3066with \uff5eas\u3068\u8a18\u8ff0\u3059\u308b\u3068\u30d5\u30a1\u30a4\u30eb\u3092\u30aa\u30d6\u30b8\u30a7\u30af\u30c8f \u3068\u3057\u3066\u6271\u3048\u307e\u3059\u3002<\/p>\n<pre>Titles = []\r\nwith open('Titles.txt', 'r') as f:  \r\n    for x in f: \r\n        Titles.append(x.rstrip(\"\\n\")) \r\n        print(x.rstrip(\"\\n\"))<\/pre>\n<p>1\u884c\u3065\u3064\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u4e0a\u8a18\u30b3\u30fc\u30c9\u3082read\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3048\u3070\u307e\u3068\u3081\u3066\u30ea\u30b9\u30c8\u306b\u3067\u304d\u307e\u3059\u306d\u3002\u6539\u884c\u30b3\u30fc\u30c9\u3082\u95a2\u4fc2\u306a\u3044\u306e\u304b\u306a\u3002\u3053\u308c\u3001\u3082\u3046\u5206\u304b\u3093\u306d\u3048\u306a\u3041\u3002<\/p>\n<pre>Titles = []\r\nwith open('Titles.txt', 'r') as f:\r\n    Titles.append(f.read())\r\nfor x in Titles:\r\n    print(x)<\/pre>\n<p>\n\u8ffd\u8a18\uff09Windows10 \u306eVisual Studio Code \u306e\u30c7\u30d0\u30c3\u30b0\u6a5f\u80fd\u3092\u4f7f\u3063\u3066\u5916\u90e8\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u8fbc\u307f\u3092\u3057\u3066\u3044\u307e\u3057\u305f\u304c\u4e00\u5411\u306b\u51fa\u529b\u3057\u3066\u304f\u308c\u306a\u3044\u306e\u3067\u3001CentOS \u306ebash \u3092\u4f7f\u3063\u305f\u3068\u3053\u308d\u6b63\u5e38\u306b\u8aad\u307f\u8fbc\u3093\u3067\u304f\u308c\u307e\u3057\u305f\u3002<\/p>\n<p>\u8a02\u6b63\uff09\u307e\u3068\u3081\u3066read\u30e1\u30bd\u30c3\u30c9\u3067\u8aad\u307f\u8fbc\u3080\u30b3\u30fc\u30c9\u306efor\u30eb\u30fc\u30d7\u306e\u53c2\u7167\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u8aa4\u308a\u304c\u3042\u308a\u307e\u3057\u305f\u306e\u3067\u4fee\u6b63\u3057\u307e\u3057\u305f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5916\u90e8\u306e.txt \u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080open \u30e1\u30bd\u30c3\u30c9\u306b\u3064\u3044\u3066\u8abf\u3079\u305f\u306e\u3067\u30e1\u30e2\u3002 python\u3067list\u3092\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3057\u3001\u8aad\u307f\u8fbc\u3080\u65b9\u6cd5(numpy\u3082\u540c\u69d8\uff01) Titles.txt Stand Still &#8211; Wave Ra &hellip; <a href=\"https:\/\/www.stuffy.site\/wordpress\/?p=6698\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">open\u30e1\u30bd\u30c3\u30c9(Python)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[98],"tags":[],"class_list":["post-6698","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6698","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6698"}],"version-history":[{"count":25,"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6698\/revisions"}],"predecessor-version":[{"id":6723,"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/6698\/revisions\/6723"}],"wp:attachment":[{"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.stuffy.site\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}