{"id":1818,"date":"2015-01-21T23:15:43","date_gmt":"2015-01-21T15:15:43","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=1818"},"modified":"2015-01-21T23:15:43","modified_gmt":"2015-01-21T15:15:43","slug":"%e5%a6%82%e4%bd%95%e5%88%a4%e6%96%ad%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%9a%84%e7%bc%96%e7%a0%81","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/1818.html","title":{"rendered":"\u5982\u4f55\u5224\u65ad\u5b57\u7b26\u4e32\u7684\u7f16\u7801"},"content":{"rendered":"<p>\u5176\u5b9e\u6587\u7ae0\u7684\u6807\u9898\u53d6\u5f97\u6709\u70b9\u5927\u4e86\uff0c\u56e0\u4e3a\u7a0b\u5e8f\u662f\u65e0\u6cd5\u51c6\u786e\u7684\u5224\u65ad\u51fa\u67d0\u4e00\u5b57\u7b26\u4e32\u7a76\u7adf\u662f\u4f7f\u7528\u4e86\u4f55\u79cd\u7f16\u7801\u65b9\u5f0f\u7684\uff08\u56e0\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u53ef\u4ee5\u5305\u542b\u5404\u79cd\u7f16\u7801\u7684\u5b57\u7b26\uff0c\u5c31\u7b97\u4eba\u5224\u65ad\u8d77\u6765\u90fd\u5f88\u56f0\u96be\uff0c\u66f4\u4f55\u51b5\u662f\u901a\u8fc7\u7b80\u5355\u7684\u7a0b\u5e8f\u4e86\uff09\uff0c\u4ece\u800c\uff0c\u8fd9\u91cc\u53ea\u662f\u5927\u6982\u7684\u5224\u65ad\u4e00\u4e0b\u5b57\u7b26\u4e32\u7684\u7f16\u7801\u65b9\u5f0f\uff0c\u7136\u540e\u5c1d\u8bd5\u6027\u7684\u53bb\u6309\u7167\u81ea\u5df1\u8ba4\u5b9a\u7684\u7f16\u7801\u65b9\u5f0f\u53bb\u8fdb\u884c\u89e3\u7801(\u5982\u679c\u9700\u8981\u7684\u8bdd)\u3002<\/p>\n<h5>1.Python\u7684\u5904\u7406\u65b9\u5f0f<\/h5>\n<h6>\u641c\u7d22\u5173\u952e\u5b57\uff1a<\/h6>\n<p><a href=\"http:\/\/search.aol.com\/aol\/search?q=use+python+to+determine+the+string+encoding\" target=\"_blank\">http:\/\/search.aol.com\/aol\/search?q=use+python+to+determine+the+string+encoding<\/a><\/p>\n<pre class=\"lang:default decode:true\">'''\nIn Python 3, all strings are sequences of Unicode characters. There is a bytes type that holds raw bytes.\nIn Python 2, a string may be of type str or of type unicode. You can tell which using code something like this:\n'''\ndef whatisthis(s):\n    if isinstance(s, str):\n        print \"ordinary string\"\n    elif isinstance(s, unicode):\n        print \"unicode string\"\n    else:\n        print \"not a string\"<\/pre>\n<pre class=\"lang:default decode:true \">'''\nHere is a small snippet to help you to guess the encoding. It guesses between latin1 and utf8 quite good. It converts a byte string to a unicode string.\nAttention: Order of encoding_guess_list is import. Example: \"latin1\" always succeeds.\n'''\nencoding_guess_list=['utf8', 'latin1']\ndef try_unicode(string, errors='strict'):\n    if isinstance(string, unicode):\n        return string\n    assert isinstance(string, str), repr(string)\n    for enc in encoding_guess_list:\n        try:\n            return string.decode(enc, errors)\n        except UnicodeError, exc:\n            continue\n    raise UnicodeError('Failed to convert %r' % string)\ndef test_try_unicode():\n    for start, should in [\n        ('\\xfc', u'\u00fc'),\n        ('\\xc3\\xbc', u'\u00fc'),\n        ('\\xbb', u'\\xbb'), # postgres\/psycopg2 latin1: RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK\n        ]:\n        result=try_unicode(start, errors='strict')\n        if not result==should:\n            raise Exception(u'Error: start=%r should=%r result=%r' % (start, should, result))<\/pre>\n<h6>\u4e00\u4e9b\u53c2\u8003\u94fe\u63a5\uff1a<\/h6>\n<ul>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/15918314\/python-detect-string-byte-encoding\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/15918314\/python-detect-string-byte-encoding<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/196345\/how-to-check-if-a-string-in-python-is-in-ascii\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/196345\/how-to-check-if-a-string-in-python-is-in-ascii<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/436220\/python-is-there-a-way-to-determine-the-encoding-of-text-file\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/436220\/python-is-there-a-way-to-determine-the-encoding-of-text-file<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/90838\/how-can-i-detect-the-encoding-codepage-of-a-text-file\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/90838\/how-can-i-detect-the-encoding-codepage-of-a-text-file<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/2144815\/how-to-know-the-encoding-of-a-file-in-python\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/2144815\/how-to-know-the-encoding-of-a-file-in-python<\/a><\/li>\n<li><a href=\"http:\/\/stackoverflow.com\/questions\/4987327\/how-do-i-check-if-a-string-is-unicode-or-ascii\" target=\"_blank\">http:\/\/stackoverflow.com\/questions\/4987327\/how-do-i-check-if-a-string-is-unicode-or-ascii<\/a><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<h5>2.PHP\u7684\u5904\u7406\u65b9\u5f0f<\/h5>\n<p>\u53c2\u8003\uff1a<a href=\"http:\/\/ixyzero.com\/blog\/archives\/680.html\" target=\"_blank\">\u5982\u4f55\u7528PHP\u68c0\u6d4b\u5b57\u7b26\u4e32\u662f\u5426\u4e3aUTF-8\u7f16\u7801<\/a><\/p>\n<p>\u5f85\u7eed\u2026\u2026<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5176\u5b9e\u6587\u7ae0\u7684\u6807\u9898\u53d6\u5f97\u6709\u70b9\u5927\u4e86\uff0c\u56e0\u4e3a\u7a0b\u5e8f\u662f\u65e0\u6cd5\u51c6\u786e\u7684\u5224\u65ad\u51fa\u67d0\u4e00\u5b57\u7b26\u4e32\u7a76\u7adf\u662f\u4f7f\u7528\u4e86\u4f55\u79cd\u7f16\u7801\u65b9\u5f0f\u7684\uff08\u56e0\u4e3a\u4e00\u4e2a\u5b57\u7b26\u4e32\u4e2d\u53ef [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,6,12],"tags":[439,217],"class_list":["post-1818","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-other","category-tools","tag-encoding","tag-unicode"],"views":4667,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1818","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=1818"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/1818\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=1818"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=1818"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=1818"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}