日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

python读取ini文件utf-16 le_Python文件编码不可以使用UTF16

發布時間:2025/3/21 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python读取ini文件utf-16 le_Python文件编码不可以使用UTF16 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. The complete Python source file should use a single encoding.

Embedding of differently encoded data is not allowed and will

result in a decoding error during compilation of the Python

source code.

Python源文件應該使用單一編碼,嵌入不同編碼的數據是不允許的(個人猜測:比如單一文件里一部分使用GBK,一部分使用BIG碼是不行的),會導致解碼錯誤。

Any encoding which allows processing the first two lines in the way indicated above is allowed as source code encoding, this includes ASCII compatible encodings as well as certain multi-byte encodings such as Shift_JIS. It does not include encodings which use two or more bytes for all characters like e.g. UTF-16. The reason for this is to keep the encoding detection algorithm in the tokenizer simple.

任何允許處理頭兩行的編碼可以作為源代碼編碼的格式,這包括ASCII兼容編碼以及某些多字節編碼,比如SHIFT_JIS。它不包括為所有字符都是有雙字節或者更多字節的編碼,比如UTF-16(注:也就是通常說的Unicode,但SHIFT_JIS也好,GBK也好,因為兼容ASCII編碼,所以都可以在Python源文件里使用)。這么做的理由是,可以使用簡單的字符在編碼探測算法里。

摘自這里:

http://legacy.python.org/dev/peps/pep-0263/

# -*- coding: UTF-8 –*-

#coding=utf-8

#coding:utf-8

#coding=gbk

結論:可以使用utf-8,如果涉及跨平臺的時候不要帶BOM,也可以采用GBK,但就是不能使用utf16。但是有意思的是,我使用PyScripter作為IDE編程,源代碼里帶中文注釋,把Python文件轉成UTF16-LE后編程和運行一點問題都沒有,還有部分優勢,比如能正確顯示200?μs,utf8下就有亂碼。但是發布的時候,可不要這樣。

這篇文章不錯:

http://www.crifan.com/python_head_meaning_for_usr_bin_python_coding_utf-8/

http://www.jb51.net/article/26543.htm

總結

以上是生活随笔為你收集整理的python读取ini文件utf-16 le_Python文件编码不可以使用UTF16的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。