{"id":753,"date":"2020-08-08T16:55:58","date_gmt":"2020-08-08T08:55:58","guid":{"rendered":"http:\/\/www.mustenaka.cn\/?p=753"},"modified":"2020-09-06T17:35:43","modified_gmt":"2020-09-06T09:35:43","slug":"pythonfixnon-ascii-character","status":"publish","type":"post","link":"https:\/\/www.mustenaka.cn\/index.php\/2020\/08\/08\/pythonfixnon-ascii-character\/","title":{"rendered":"Python\u89e3\u51b3Non-ASCII character &#8216;xe6&#8217;"},"content":{"rendered":"<h3>Python\u89e3\u51b3Non-ASCII character &#8216;xe6&#8217;<\/h3>\n<p>\u5176\u5b9e\u975e\u5e38\u7b80\u5355\uff0cpython\u518d\u5199\u4ee3\u7801\u8fc7\u7a0b\u4e2d\u5f53\u7528\u5230\u4e2d\u6587\u6ce8\u91ca\u65f6\u5019\u4f1a\u51fa\u73b0Non-ASCII character bug<br \/>\n\u63a7\u5236\u9762\u677f\u4e2d\u4ee3\u7801\u63d0\u793a\u662f\u8fd9\u6837\u7684\uff1a<\/p>\n<p>SyntaxError: Non-ASCII character \u2018\u4e00\u4e2a\u4e2d\u6587\u6ce8\u91ca\u5b57\u7b26\u2019 in file \u6587\u4ef6\u540d\u79f0.py on line \u4e00\u4e2a\u6bb5\u843d, but no encoding declared; see<span>\u00a0<\/span><a href=\"http:\/\/python.org\/dev\/peps\/pep-0263\/\" rel=\"nofollow\" class=\"md-opjjpmhoiojifppkkcdabiobhakljdgm_doc\">http:\/\/python.org\/dev\/peps\/pep-0263\/<\/a><span>\u00a0<\/span>for details<br \/>\n\u8fd9\u5c31\u610f\u5473\u7740\u53d1\u751f\u4e86\u4e2d\u6587\u4e71\u7801\u95ee\u9898<\/p>\n<p>\u53e6\u5916\uff0c\u6709\u4e9b\u7535\u8111\u547d\u540d\u4e0d\u9700\u8981\u6dfb\u52a0coding\uff1autf-8\u5f3a\u5236\u6307\u5b9a\u7684\uff0c\u53ef\u4ee5\u8fd0\u884c\u4e2d\u6587\uff0c\u53ef\u5728\u53e6\u5916\u4e00\u4e9b\u7535\u8111\u4e0a\u9762\u5c31\u9700\u8981\u5f3a\u5236\u6307\u5b9a\u4e86\uff0c\u8fd9\u53ef\u80fd\u662f\u56e0\u4e3a\u7f16\u8f91\u5668\u548c\u7f16\u8bd1\u5668\u6709\u5173\uff0cvscode\u515a\u5efa\u8bae\u88c5\u4e2acode runner\u540c\u65f6\u5b89\u88c5\u4e2d\u6587\u8865\u4e01\u3002<\/p>\n<ol>\n<li>\u89e3\u51b3\u529e\u6cd5\uff1a\u7f16\u5199\u7f16\u7801\u65f6\u5019Python\u9ed8\u8ba4\u4e3aASCII\u7f16\u7801\u3002<\/li>\n<li>ASCII\u7f16\u7801\uff1a\u662f\u57fa\u4e8e\u62c9\u4e01\u5b57\u6bcd\u7684\u4e00\u5957\u7535\u8111\u7f16\u7801\u7cfb\u7edf\u3002\u5b83\u4e3b\u8981\u7528\u4e8e\u663e\u793a\u73b0\u4ee3\u82f1\u8bed\uff0c\u800c\u5176\u6269\u5c55\u7248\u672cEASCII\u5219\u53ef\u4ee5\u90e8\u5206\u652f\u6301\u5176\u4ed6\u897f\u6b27\u8bed\u8a00\uff0c\u5e76\u7b49\u540c\u4e8e\u56fd\u9645\u6807\u51c6ISO\/IEC 646\uff0c\u4ed6\u5e76\u4e0d\u652f\u6301\u4e2d\u6587\u7f16\u7801\uff0c\u4e2d\u6587\u7f16\u7801\u96c6\u5e38\u89c1\u7684\u6709GBK\u548cUTF-8\u3002\uff08\u66f4\u5e38\u7528UTF-8\uff09<\/li>\n<\/ol>\n<p>\u6240\u4ee5\u8981\u5b9a\u4e49\u6709\u4e2d\u6587\u7684\u6e90\u4ee3\u7801\u7f16\u7801\uff0c\u5fc5\u987b\u6709\u4e00\u4e2a\u795e\u5947\u7684\u6ce8\u91ca\u4ee5\u5f3a\u5236\u6307\u5b9a\u7f16\u7801\u96c6\uff0c\u653e\u5728\u6587\u4ef6\u7684\u5f00\u5934\u3002\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<blockquote><p>#-<em>&#8211; coding: &#8211;<\/em>&#8211;<\/p><\/blockquote>\n<p>\u4e2d\u6587\u7684encoding\u5c31\u7528\u4e0b\u5217\u7f16\u7801\u5c31\u53ef\u4ee5\u5566\uff01<\/p>\n<blockquote><p>#-<em>&#8211; coding:utf8 &#8211;<\/em>&#8211;<\/p><\/blockquote>\n<p>\u6709\u4e00\u4e9b\u89e3\u91ca\u6587\u6863\u8bf4\u8fd8\u8981\u518d\u6dfb\u52a0\u4e00\u884c #!\/usr\/bin\/python \u8fd9\u4e2a\u5176\u5b9e\u662f\u6307\u5b9aPython\u7f16\u8bd1\u5668\u6240\u5728\u4f55\u5904\uff0c\u8fd9\u4e2a\u8def\u5f84\u5f88\u660e\u663e\u6765\u81ea\u4e8eLinux\u64cd\u4f5c\u7cfb\u7edf\uff0cWindows\u8fd9\u6837\u5199\u5927\u53ef\u4e0d\u5fc5\u3002<\/p>\n<p>\u6b64\u5916\uff0c\u5982\u679c\u4f60\u4f7f\u7528Anaconda\uff0cminiconda\u8fd9\u6837\u7684\u865a\u62df\u73af\u5883\u7ba1\u7406\u5de5\u5177\uff0c\u6307\u5b9aPython\u7528\u7edd\u5bf9\u8def\u5f84\u7684\u65b9\u5f0f\u6307\u5b9a\u4e5f\u8fc7\u4e8e\u9ebb\u70e6\uff0c\u4e0d\u5982\u5c31\u591a\u719f\u6089\u719f\u6089conda\u7684\u547d\u4ee4\uff0c\u591a\u7528activate\u6fc0\u6d3b\u5c31\u884c\uff0c\u8fd8\u6709\u4f60\u4f7f\u7528Pycharm\u7684\u8bdd\u63d0\u524d\u914d\u7f6e\u597d\u4e5f\u662fOK\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\u89e3\u51b3Non-ASCII character &#8216;xe6&#8217; \u5176\u5b9e\u975e\u5e38 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30,13],"tags":[31],"class_list":["post-753","post","type-post","status-publish","format-standard","hentry","category-python","category-vscode","tag-python"],"views":4133,"_links":{"self":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/753","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/comments?post=753"}],"version-history":[{"count":4,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/753\/revisions"}],"predecessor-version":[{"id":758,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/posts\/753\/revisions\/758"}],"wp:attachment":[{"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/media?parent=753"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/categories?post=753"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mustenaka.cn\/index.php\/wp-json\/wp\/v2\/tags?post=753"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}