{"id":59,"date":"2014-06-19T23:42:13","date_gmt":"2014-06-19T14:42:13","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=59"},"modified":"2019-10-19T06:23:40","modified_gmt":"2019-10-18T21:23:40","slug":"blog19","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog19\/","title":{"rendered":"(19) \u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u8aad\u307f\u66f8\u304d"},"content":{"rendered":"<p>\u307e\u305a\u306f\u3001Python\u3092\u4f7f\u3063\u3066\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002<\/p>\n<pre>\r\n>>> fh = <span class=\"my_fc_deeppinkB\">open<\/span>('data.txt','w')\r\n>>> fh.<span class=\"my_fc_deeppinkB\">write<\/span>('hello\\n')\r\n>>> fh.<span class=\"my_fc_deeppinkB\">write<\/span>('see you!\\n')\r\n>>> fh.<span class=\"my_fc_deeppinkB\">close<\/span>()\r\n>>>\r\n[user@dog-server]$ ls\r\ndata.txt\r\n[user@dog-server]$\r\n[user@dog-server]$ cat data.txt\r\nhello\r\nsee you!\r\n<\/pre>\n<p>\u6b21\u306b\u3001\u4f5c\u6210\u3057\u305f\u30d5\u30a1\u30a4\u30eb\u3092 Python\u3067\u8aad\u307f\u8fbc\u3080\u3002<\/p>\n<pre>\r\n>>> fh = <span class=\"my_fc_deeppinkB\">open<\/span>('data.txt','r')\r\n>>>\r\n>>> data = fh.<span class=\"my_fc_deeppinkB\">read<\/span>()\r\n>>> data\r\n'hello\\nsee you!\\n'\r\n>>>\r\n>>> print data\r\nhello\r\nsee you!\r\n>>>\r\n>>> ary = data.split('\\n')\r\n>>> ary\r\n['hello', 'see you!', '']\r\n>>> ary[0]\r\n'hello'\r\n>>> ary[1]\r\n'see you!'\r\n<\/pre>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>\u307e\u305a\u306f\u3001Python\u3092\u4f7f\u3063\u3066\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u4f5c\u6210\u3059\u308b\u3002 >>> fh = open(&#8216;data.txt&#8217;,&#8217;w&#8217;) >>> fh.write(&#8216;hello\\n&#8217;) >>> fh.write(&#8216;see you!\\n&#8217;) \u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog19\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-59","post","type-post","status-publish","format-standard","hentry","category-8"],"views":2041,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/59","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/comments?post=59"}],"version-history":[{"count":8,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/59\/revisions"}],"predecessor-version":[{"id":2596,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/59\/revisions\/2596"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=59"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=59"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=59"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}