「PyScripter 日本語ファイルエラーの対応」の版間の差分
ナビゲーションに移動
検索に移動
| 1行目: | 1行目: | ||
| − | ==PyScripter 日本語ファイルエラーの対応== | + | ==[[PyScripter 日本語ファイルエラーの対応]]== |
| − | [[Python]] | [[PyScripter]] | | + | [[Python]] | [[PyScripter]] | [[Category:文字化け]] |
===ファイルのパスに日本語が入るとエラー=== | ===ファイルのパスに日本語が入るとエラー=== | ||
| 27行目: | 27行目: | ||
if encoding != "ascii": | if encoding != "ascii": | ||
# On Non-Unicode builds this will raise an AttributeError... | # On Non-Unicode builds this will raise an AttributeError... | ||
| − | sys.setdefaultencoding(encoding) # Needs Python Unicode build ! | + | sys.setdefaultencoding(encoding) # Needs [[Python]] Unicode build ! |
===OK=== | ===OK=== | ||
[[File:1022_pyscripter_encode_err02.jpg]] | [[File:1022_pyscripter_encode_err02.jpg]] | ||
2020年2月16日 (日) 04:30時点における最新版
PyScripter 日本語ファイルエラーの対応
Python | PyScripter |
ファイルのパスに日本語が入るとエラー
<blockquote>UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-10: ordinal not in range(128)</blockquote>
%PYTHON_HOME%\Lib\site.py を編集
- Enable to support locale aware default string encodings. の条件を 0 -> 1 に
def setencoding():
"""Set the string encoding used by the Unicode implementation. The
default is 'ascii', but if you're willing to experiment, you can
change this."""
encoding = "ascii" # Default value set by _PyUnicode_Init()
### ↓↓↓ ここを、0 -> 1 に変更
if 1:
# Enable to support locale aware default string encodings.
import locale
loc = locale.getdefaultlocale()
if loc[1]:
encoding = loc[1]
if 0:
# Enable to switch off string to Unicode coercion and implicit
# Unicode to string conversion.
encoding = "undefined"
if encoding != "ascii":
# On Non-Unicode builds this will raise an AttributeError...
sys.setdefaultencoding(encoding) # Needs Python Unicode build !
OK
© 2006 矢木浩人

