{"id":7604,"date":"2016-11-06T20:18:20","date_gmt":"2016-11-06T11:18:20","guid":{"rendered":"http:\/\/www.gesource.jp\/weblog\/?p=7604"},"modified":"2017-07-16T00:18:26","modified_gmt":"2017-07-15T15:18:26","slug":"python%e3%81%a7%e3%83%86%e3%82%ad%e3%82%b9%e3%83%88%e3%83%95%e3%82%a1%e3%82%a4%e3%83%ab%e3%81%ae%e6%94%b9%e8%a1%8c%e3%82%b3%e3%83%bc%e3%83%89%e3%82%92crlf%e3%81%8b%e3%82%89lf%e3%81%ab%e5%a4%89","status":"publish","type":"post","link":"https:\/\/www.gesource.jp\/weblog\/?p=7604","title":{"rendered":"Python\u3067\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u6539\u884c\u30b3\u30fc\u30c9\u3092CRLF\u304b\u3089LF\u306b\u5909\u63db\u3059\u308b\u306b\u306f"},"content":{"rendered":"<p>Python\u3067\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u6539\u884c\u30b3\u30fc\u30c9\u3092CRLF\u304b\u3089LF\u306b\u5909\u63db\u3057\u305f\u3044\u3002<\/p>\n<p>\u6587\u5b57\u5217\u3092\u6539\u884c\u30b3\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u3066\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3059\u308b\u65b9\u6cd5\u304c\u898b\u3064\u304b\u3089\u306a\u304b\u3063\u305f\u3002<\/p>\n<p>\u30d0\u30a4\u30c8\u5217\u306b\u3057\u3066\u4fdd\u5b58\u3059\u308b\u3053\u3068\u3067\u5b9f\u73fe\u3067\u304d\u305f\u3002<\/p>\n<h3>\u74b0\u5883<\/h3>\n<ul>\n<li>Windows 10<\/li>\n<li>Python 2.5.1<\/li>\n<\/ul>\n<h3>\u624b\u9806<\/h3>\n<p>(1) \u6539\u884c\u30b3\u30fc\u30c9\u304cCRLF(&#92;r&#92;n)\u306b\u306a\u3063\u3066\u3044\u308b\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u3080\u3002<\/p>\n<pre><code>with open('test1.txt', 'r', encoding='utf-8') as a_file:\n  txt = a_file.read()\n<\/code><\/pre>\n<p>(2) \u6539\u884c\u30b3\u30fc\u30c9CR(&#92;r)\u3092\u524a\u9664\u3059\u308b\u3002<\/p>\n<pre><code>txt = txt.replace('\\r', '')\n<\/code><\/pre>\n<p>(3) \u30d5\u30a1\u30a4\u30eb\u3092\u30d0\u30a4\u30ca\u30ea\u30e2\u30fc\u30c9\u3067\u958b\u304f\u3002<\/p>\n<pre><code>with open('test2.txt', 'wb') as a_file:\n<\/code><\/pre>\n<p>(4) \u30d5\u30a1\u30a4\u30eb\u306b\u3001\u6587\u5b57\u5217\u3092UTF-8\u306e\u30d0\u30a4\u30c8\u5217\u306b\u3057\u3066\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<pre><code>a_file.write(txt.encode('utf-8'))\n<\/code><\/pre>\n<h3>\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n<pre><code>#! python3\n\n# \u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u304b\u3089\u6587\u5b57\u5217\u3092\u8aad\u307f\u8fbc\u3080\nwith open('test1.txt', 'r', encoding='utf-8') as a_file:\n  txt = a_file.read()\n\n# \u8aad\u307f\u8fbc\u3093\u3060\u6587\u5b57\u5217\u306eCR(\\r)\u3092\u524a\u9664\u3059\u308b\u3002\ntxt = txt.replace('\\r', '')\n\n# \u30d5\u30a1\u30a4\u30eb\u3092\u30d0\u30a4\u30ca\u30ea\u30e2\u30fc\u30c9\u3067\u958b\u304f\nwith open('test2.txt', 'wb') as a_file:\n  # \u6587\u5b57\u5217\u3092\u30d0\u30a4\u30c8\u5217\u306b\u3057\u3066\u4fdd\u5b58\u3059\u308b\n  a_file.write(txt.encode('utf-8'))\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python\u3067\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u6539\u884c\u30b3\u30fc\u30c9\u3092CRLF\u304b\u3089LF\u306b\u5909\u63db\u3057\u305f\u3044\u3002 \u6587\u5b57\u5217\u3092\u6539\u884c\u30b3\u30fc\u30c9\u3092\u6307\u5b9a\u3057\u3066\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3059\u308b\u65b9\u6cd5\u304c\u898b\u3064\u304b\u3089\u306a\u304b\u3063\u305f\u3002 \u30d0\u30a4\u30c8\u5217\u306b\u3057\u3066\u4fdd\u5b58\u3059\u308b\u3053\u3068\u3067\u5b9f\u73fe\u3067\u304d\u305f\u3002 \u74b0\u5883 Windows  &#8230;<\/p>\n<p><a href=\"https:\/\/www.gesource.jp\/weblog\/?p=7604\" class=\"more-link\">Continue reading &lsquo;Python\u3067\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\u306e\u6539\u884c\u30b3\u30fc\u30c9\u3092CRLF\u304b\u3089LF\u306b\u5909\u63db\u3059\u308b\u306b\u306f&rsquo; &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7],"tags":[143],"class_list":["post-7604","post","type-post","status-publish","format-standard","hentry","category-python","tag-python"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/7604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=7604"}],"version-history":[{"count":0,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=\/wp\/v2\/posts\/7604\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=7604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=7604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gesource.jp\/weblog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=7604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}