{"id":1393,"date":"2014-01-23T16:00:44","date_gmt":"2014-01-23T21:00:44","guid":{"rendered":"http:\/\/www.a2life.info\/w\/?p=1393"},"modified":"2014-01-27T13:59:59","modified_gmt":"2014-01-27T18:59:59","slug":"python3-%e3%81%ae%e6%96%87%e5%ad%97%e5%88%97%e3%80%80%e8%a6%9a%e6%9b%b8","status":"publish","type":"post","link":"https:\/\/www.a2life.info\/w\/?p=1393","title":{"rendered":"Python3 \u306e\u6587\u5b57\u5217\u3000\u899a\u66f8"},"content":{"rendered":"<p>Python3\u3067\u306fstring = unicode<\/p>\n<p>string \u3092\u30a2\u30ec\u30fc\u3068\u3057\u3066\u8003\u3048\u3066slice \u3059\u308b\u3068\u304d\u3082\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u3092\u6c17\u306b\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u3002<\/p>\n<pre>\r\n>>> s = 'python\u306b\u3001\u3069\u3063\u3077\u308a\u3064\u304b\u308b'\r\n>>> len(s)\r\n15\r\n>>> s[8:]\r\n'\u3069\u3063\u3077\u308a\u3064\u304b\u308b'\r\n>>> s[:6]\r\n'python'\r\n>>> s[:7]+s[8:12]\r\n'python\u306b\u3069\u3063\u3077\u308a'\r\n>>> \r\n<\/pre>\n<p>\u305f\u3060\u3001\u3088\u3044\u3053\u3068\u3070\u304b\u308a\u3067\u306f\u306a\u304f\u3001file\u306a\u3069\u304b\u3089\u306eIO\u51e6\u7406\u3067\u306f\u8aad\u307f\u8fbc\u307e\u308c\u308b\u306e\u304c\u30d0\u30a4\u30c8\u5217\u306b\u306a\u308b\u305f\u3081\u5909\u63db\u3092\u3057\u3066\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002\u3000Python 2.7\u3067\u306f\u5fc5\u8981\u306a\u304b\u3063\u305f\u306e\u3067Python2.x\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u79fb\u690d\u3059\u308b\u3068\u304d\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3002encode()\u3068\u3057\u3066unicode\u306e\u30d0\u30a4\u30c8\u5217\u8868\u793a\u3001decode()\u3067Unicode\u306e\u30d0\u30a4\u30c8\u5217\u3092Unicode\u306e\u6587\u5b57\u5217\u8868\u793a<\/p>\n<pre>\r\n>>> s.encode()\r\nb'python\\xe3\\x81\\xab\\xe3\\x80\\x81\\xe3\\x81\\xa9\\xe3\\x81\\xa3\\xe3\\x81\\xb7\\xe3\\x82\\x8a\\xe3\\x81\\xa4\\xe3\\x81\\x8b\\xe3\\x82\\x8b'\r\n>>> b'python\\xe3\\x81\\xab\\xe3\\x80\\x81\\xe3\\x81\\xa9\\xe3\\x81\\xa3\\xe3\\x81\\xb7\\xe3\\x82\\x8a\\xe3\\x81\\xa4\\xe3\\x81\\x8b\\xe3\\x82\\x8b'.decode()\r\n'python\u306b\u3001\u3069\u3063\u3077\u308a\u3064\u304b\u308b'\r\n>>> \r\n<\/pre>\n<p>\u6700\u521d\u306e\u30d0\u30a4\u30c8\u5217\u304cUnicode\u4ee5\u5916\u306e\u6587\u5b57\u5217\u306e\u5834\u5408\u306fencoding\u3092\u6307\u5b9a<\/p>\n<pre>\r\n>>> chara = b'\\x63\\x6c\\x69\\x63\\x68\\xe9'\r\n>>> print(chara)\r\nb'clich\\xe9'\r\n>>> print(chara.decode('latin-1'))\r\nclich\u00e9\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Python3\u3067\u306fstring = unicode string \u3092\u30a2\u30ec\u30fc\u3068\u3057\u3066\u8003\u3048\u3066slice \u3059\u308b\u3068\u304d\u3082\u30de\u30eb\u30c1\u30d0\u30a4\u30c8\u6587\u5b57\u3092\u6c17\u306b\u3059\u308b\u5fc5\u8981\u304c\u306a\u3044\u3002 >>> s = &#8216;python\u306b\u3001\u3069\u3063\u3077\u308a\u3064\u304b\u308b&#8217; >>> len(s) 15 >>> s[8:] &#8216;\u3069\u3063\u3077\u308a\u3064\u304b\u308b&#8217; >>> s[:6] &#8216;python&#8217; >>> s[:7]+s[8:12] &#8216;python\u306b\u3069\u3063\u3077\u308a&#8217; >>> \u305f\u3060\u3001\u3088\u3044\u3053\u3068\u3070\u304b\u308a\u3067\u306f\u306a\u304f\u3001file\u306a\u3069\u304b\u3089\u306eIO\u51e6\u7406\u3067\u306f\u8aad\u307f\u8fbc\u307e\u308c\u308b\u306e\u304c\u30d0\u30a4\u30c8\u5217\u306b\u306a\u308b\u305f\u3081\u5909\u63db\u3092\u3057\u3066\u3042\u3052\u308b\u5fc5\u8981\u304c\u3042\u308b\u3002\u3000Python 2.7\u3067\u306f\u5fc5\u8981\u306a\u304b\u3063\u305f\u306e\u3067Python2.x\u306e\u30d7\u30ed\u30b0\u30e9\u30e0\u3092\u79fb\u690d\u3059\u308b\u3068\u304d\u306b\u6ce8\u610f\u304c\u5fc5\u8981\u3002encode()\u3068\u3057\u3066unicode\u306e\u30d0\u30a4\u30c8\u5217\u8868\u793a\u3001decode()\u3067Unicode\u306e\u30d0\u30a4\u30c8\u5217\u3092Unicode\u306e\u6587\u5b57\u5217\u8868\u793a >>> s.encode() b&#8217;python\\xe3\\x81\\xab\\xe3\\x80\\x81\\xe3\\x81\\xa9\\xe3\\x81\\xa3\\xe3\\x81\\xb7\\xe3\\x82\\x8a\\xe3\\x81\\xa4\\xe3\\x81\\x8b\\xe3\\x82\\x8b&#8217; >>> b&#8217;python\\xe3\\x81\\xab\\xe3\\x80\\x81\\xe3\\x81\\xa9\\xe3\\x81\\xa3\\xe3\\x81\\xb7\\xe3\\x82\\x8a\\xe3\\x81\\xa4\\xe3\\x81\\x8b\\xe3\\x82\\x8b&#8217;.decode() &#8216;python\u306b\u3001\u3069\u3063\u3077\u308a\u3064\u304b\u308b&#8217; >>> \u6700\u521d\u306e\u30d0\u30a4\u30c8\u5217\u304cUnicode\u4ee5\u5916\u306e\u6587\u5b57\u5217\u306e\u5834\u5408\u306fencoding\u3092\u6307\u5b9a >>> chara = b&#8217;\\x63\\x6c\\x69\\x63\\x68\\xe9&#8242; >>> print(chara) b&#8217;clich\\xe9&#8242; >>> print(chara.decode(&#8216;latin-1&#8217;)) clich\u00e9<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[49],"class_list":["post-1393","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-python3"],"_links":{"self":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1393"}],"version-history":[{"count":2,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1393\/revisions"}],"predecessor-version":[{"id":1398,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=\/wp\/v2\/posts\/1393\/revisions\/1398"}],"wp:attachment":[{"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1393"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.a2life.info\/w\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}