2016-12-27 7 views
1

私はPythonには新しく、このエンコーディングのことについて本当に混乱しています。これまでのところ、私は "エンコーディング" の次のタイプについて読んだ:sys.stdout.encoding、locale.getpreferredencoding()、およびsys.getdefaultencoding()の違いは何ですか?

import sys 
import locale 

print (sys.stdout.encoding) 
print (locale.getpreferredencoding()) 
print (sys.getdefaultencoding()) 

出力:

utf8 
cp1252 
utf-8 

違いは何ですか?

答えて

0

簡単に言えば、エンコーディングはあなたのデータがメモリ内に保存される方法です。さまざまな方法で、より多くの文字と情報を使用できます。綿密な説明については、あなたは物事がどちらかが物理的に、またはthe coding functionのいずれかを使用してエンコードタイプを呼び出すことによって保存されている方法を変更することができますPythonでいずれかhttp://kunststube.net/encoding/、またはWikipedia

を読むことが歓迎以上です。

python3.xの環境では、sys.stdout.encodingsys.getdefaultencoding()の間に違いはありません。彼らは両方とも8バイトコードユニットを使用しています(最も標準的です)。好ましいエンコーディング、locale.getpreferredencoding()cp1252)は、latin1のウィンドウバージョンです。

どのメソッド/関数でも迅速なフィードバックを得たい場合は、いつでもhelpコマンドを使用できます。

例:

>>> import locale 
>>> help(locale.getpreferredencoding) 

出力:

Help on function getpreferredencoding in module locale: 

getpreferredencoding(do_setlocale=True) 
    Return the charset that the user is likely using, 
    according to the system configuration. 
(END) 
関連する問題