| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

PyScripter 日本語ファイルエラーの対応

提供: MyMemoWiki
ナビゲーションに移動 検索に移動

PyScripter 日本語ファイルエラーの対応

Python | PyScripter |

ファイルのパスに日本語が入るとエラー

<blockquote>UnicodeEncodeError: 'ascii' codec can't encode characters in position 8-10: ordinal not in range(128)</blockquote>

1021 pyscripter encode err01.jpg

%PYTHON_HOME%\Lib\site.py を編集

  • Enable to support locale aware default string encodings. の条件を 0 -> 1 に
  1. def setencoding():
  2. """Set the string encoding used by the Unicode implementation. The
  3. default is 'ascii', but if you're willing to experiment, you can
  4. change this."""
  5. encoding = "ascii" # Default value set by _PyUnicode_Init()
  6. ### ↓↓↓ ここを、0 -> 1 に変更
  7. if 1:
  8. # Enable to support locale aware default string encodings.
  9. import locale
  10. loc = locale.getdefaultlocale()
  11. if loc[1]:
  12. encoding = loc[1]
  13. if 0:
  14. # Enable to switch off string to Unicode coercion and implicit
  15. # Unicode to string conversion.
  16. encoding = "undefined"
  17. if encoding != "ascii":
  18. # On Non-Unicode builds this will raise an AttributeError...
  19. sys.setdefaultencoding(encoding) # Needs Python Unicode build !

OK

1022 pyscripter encode err02.jpg