{"data":{"slug":"discovered-e0bd4a1e86805c9bb246bc73aa159250302ca33373b22f0c","title":"Script Encoding","summary":"Ensure scripts handle non-ASCII characters using UTF-8 encoding explicitly, avoiding reliance on the environment's locale settings. This prevents errors when running scripts in environments with different default encodings, such as Windows with cp932.","url":"https:\/\/skillshunter.net\/skills\/discovered-e0bd4a1e86805c9bb246bc73aa159250302ca33373b22f0c","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/discovered-e0bd4a1e86805c9bb246bc73aa159250302ca33373b22f0c","markdown_url":"https:\/\/skillshunter.net\/skills\/discovered-e0bd4a1e86805c9bb246bc73aa159250302ca33373b22f0c.md","download_url":"https:\/\/skillshunter.net\/skills\/discovered-e0bd4a1e86805c9bb246bc73aa159250302ca33373b22f0c\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before running the script, set the environment to a locale that does not use UTF-8 (e.g., cp932) to test the encoding handling. The first deliverable is a script with UTF-8 encoding explicitly configured for input and output.","instructions":"---\ndescription: \u30b9\u30af\u30ea\u30d7\u30c8\u306e\u5165\u51fa\u529b\u3092\u74b0\u5883\u306e\u30ed\u30b1\u30fc\u30eb\u306b\u4f9d\u3089\u305b\u306a\u3044\u66f8\u304d\u65b9\u3067\u3042\u308b\u3002\u975e ASCII \u3092\u51fa\u3059\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u66f8\u304f\u3068\u304d\u3001\u6587\u5b57\u30b3\u30fc\u30c9\u3067\u843d\u3061\u305f\u3068\u304d\u306b\u4f7f\u3046\u3002\nname: script-encoding\n---\n\n# script-encoding \u2014 \u30ed\u30b1\u30fc\u30eb\u306b\u4f9d\u3089\u306a\u3044\u5165\u51fa\u529b\n\n\u65e5\u672c\u8a9e\u3084\u8a18\u53f7\u3092\u51fa\u3059\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u3001\u5b9f\u884c\u74b0\u5883\u306e\u30ed\u30b1\u30fc\u30eb\u6b21\u7b2c\u3067\u843d\u3061\u308b\u3002\u843d\u3061\u308b\u74b0\u5883\u3068\u843d\u3061\u306a\u3044\u74b0\u5883\u304c\u3042\u308b\u305f\u3081\u3001\u66f8\u3044\u305f\u672c\u4eba\u306e\u624b\u5143\u3067\u306f\u901a\u3063\u3066\u3057\u307e\u3046\u3002\u5165\u51fa\u529b\u306e\u7b26\u53f7\u5316\u3092\u74b0\u5883\u306b\u805e\u304b\u305a\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u306e\u5074\u3067 UTF-8 \u306b\u6c7a\u3081\u308b\u3002\n\n## \u4f55\u304c\u8d77\u304d\u308b\u304b\n\nPython \u306f\u6a19\u6e96\u5165\u51fa\u529b\u306e\u7b26\u53f7\u5316\u3092\u5b9f\u884c\u6642\u306e\u30ed\u30b1\u30fc\u30eb\u304b\u3089\u6c7a\u3081\u308b\u3002Windows \u306e\u65e5\u672c\u8a9e\u74b0\u5883\u3067\u306f\u3053\u308c\u304c cp932 \u306b\u306a\u308a\u3001cp932 \u306b\u7121\u3044\u6587\u5b57\u3092\u8aad\u307f\u66f8\u304d\u3057\u305f\u6642\u70b9\u3067\u843d\u3061\u308b\u3002\n\n- \u843d\u3061\u308b\u306e\u306f\u30d1\u30a4\u30d7\u30fb\u30ea\u30c0\u30a4\u30ec\u30af\u30c8\u306e\u3068\u304d\u3060\u3051\n  - \u30b3\u30f3\u30bd\u30fc\u30eb\u3078\u76f4\u7d50\u3057\u3066\u3044\u308c\u3070 UTF-8 \u304c\u4f7f\u308f\u308c\u308b\n  - \u624b\u3067\u53e9\u304f\u3068\u901a\u308a\u3001\u4ed6\u306e\u30b3\u30de\u30f3\u30c9\u3078\u7e4b\u3044\u3060\u77ac\u9593\u306b\u843d\u3061\u308b\n  - \u30a8\u30fc\u30b8\u30a7\u30f3\u30c8\u304b\u3089\u306e\u5b9f\u884c\u306f\u5e38\u306b\u30d1\u30a4\u30d7\u306a\u306e\u3067\u5fc5\u305a\u8e0f\u3080\n- \u30b3\u30f3\u30bd\u30fc\u30eb\u306e\u30b3\u30fc\u30c9\u30da\u30fc\u30b8\uff08`chcp`\uff09\u306f\u95a2\u4fc2\u3057\u306a\u3044\n- \u5f15\u304d\u91d1\u306f\u7d75\u6587\u5b57\u3060\u3051\u3067\u306f\u306a\u3044\n  - `\u2014`\uff08U+2014\uff09\u306e\u3088\u3046\u306a\u3001\u65e5\u672c\u8a9e\u306e\u6587\u66f8\u306b\u3075\u3064\u3046\u306b\u51fa\u308b\u8a18\u53f7\u304c cp932 \u306b\u7121\u3044\n- Linux\u30fbmacOS \u3067\u306f\u65e2\u5b9a\u304c UTF-8 \u306a\u306e\u3067\u8d77\u304d\u306a\u3044\n  - \u5bfe\u8c61\u74b0\u5883\u304c Linux \u3067\u3082\u3001\u66f8\u304d\u624b\u306e\u624b\u5143\u304c Windows \u306a\u3089\u843d\u3061\u308b\n\n\u30b7\u30a7\u30eb\uff08bash\uff09\u306f\u6587\u5b57\u5217\u3092\u30d0\u30a4\u30c8\u5217\u306e\u307e\u307e\u6d41\u3059\u306e\u3067\u3001\u3053\u306e\u554f\u984c\u306f\u8d77\u304d\u306a\u3044\u3002\n\n## \u6c7a\u307e\u308a\n\n\u975e ASCII \u3092\u8aad\u307f\u66f8\u304d\u3059\u308b\u306a\u3089\u3001\u7b26\u53f7\u5316\u3092\u74b0\u5883\u306b\u805e\u304b\u305a\u660e\u793a\u3059\u308b\u3002\n\nPython \u3067\u306f\u3001\u6700\u521d\u306e\u5165\u51fa\u529b\u3088\u308a\u524d\u306b\u6b21\u3092\u7f6e\u304f\u3002UTF-8 \u304c\u65e2\u5b9a\u306e\u74b0\u5883\u3067\u306f\u4f55\u3082\u5909\u308f\u3089\u306a\u3044\u3002\n\n```python\nsys.stdin.reconfigure(encoding=\"utf-8\", errors=\"replace\")\nsys.stdout.reconfigure(encoding=\"utf-8\", errors=\"replace\")\nsys.stderr.reconfigure(encoding=\"utf-8\", errors=\"replace\")\n```\n\n\u30d5\u30a1\u30a4\u30eb\u3092\u958b\u304f\u3068\u304d\u3082\u540c\u3058\u3067\u3042\u308b\u3002`open()` \u306e\u65e2\u5b9a\u306e\u7b26\u53f7\u5316\u3082\u30ed\u30b1\u30fc\u30eb\u304b\u3089\u6c7a\u307e\u308b\u305f\u3081\u3001`open(path, encoding=\"utf-8\")` \u3068\u66f8\u304f\u3002\n\n\u547c\u3076\u5074\u3067 `PYTHONUTF8=1` \u3084 `PYTHONIOENCODING=utf-8` \u3092\u7acb\u3066\u308b\u5f62\u306f\u63a1\u7528\u3057\u306a\u3044\u3002\u547c\u3076\u4eba\u304c\u6bce\u56de\u899a\u3048\u3066\u3044\u308b\u5fc5\u8981\u304c\u3042\u308a\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u6e21\u3057\u305f\u5148\u3067\u306f\u52b9\u304b\u306a\u3044\u3002\n\n## \u76f4\u3063\u305f\u304b\u3092\u78ba\u304b\u3081\u308b\n\n\u624b\u5143\u304c UTF-8 \u3060\u3068\u3001\u76f4\u3063\u3066\u3044\u306a\u304f\u3066\u3082\u901a\u308b\u3002\u30ed\u30b1\u30fc\u30eb\u3092 cp932 \u306b\u898b\u305b\u304b\u3051\u3066\u78ba\u304b\u3081\u308b\u3002\n\n```sh\nPYTHONIOENCODING=cp932 <\u3075\u3060\u3093\u306e\u547c\u3073\u51fa\u3057>\n```\n\n\u975e ASCII \u3092\u542b\u3080\u5165\u529b\u3092\u6d41\u3057\u3001\u7d42\u4e86 0 \u3067 UTF-8 \u306e\u51fa\u529b\u304c\u51fa\u308c\u3070\u76f4\u3063\u3066\u3044\u308b\u3002cp932 \u306e\u5909\u63db\u8868\u306f Python \u306b\u540c\u68b1\u3055\u308c\u3066\u3044\u308b\u306e\u3067\u3001Linux\u30fbmacOS \u3067\u3082\u540c\u3058\u78ba\u8a8d\u304c\u3067\u304d\u308b\u3002\n\n## \u843d\u3061\u305f\u3068\u304d\u306e\u8aad\u307f\u5206\u3051\n\n| \u75c7\u72b6 | \u51fa\u3069\u3053\u308d |\n| --- | --- |\n| `UnicodeEncodeError: 'cp932' codec can't encode character` | \u51fa\u529b |\n| `UnicodeDecodeError: 'cp932' codec can't decode byte` | \u5165\u529b |\n| \u843d\u3061\u305a\u306b `\\u2705` \u306e\u5f62\u3067\u51fa\u308b | \u6a19\u6e96\u30a8\u30e9\u30fc |\n\n\u6a19\u6e96\u30a8\u30e9\u30fc\u306f\u65e2\u5b9a\u304c `backslashreplace` \u3067\u3042\u308b\u305f\u3081\u3001\u843d\u3061\u305a\u306b\u8aad\u3081\u306a\u3044\u5f62\u3078\u5316\u3051\u308b\u3002\n","use_cases":["Ensure scripts with non-ASCII characters run without errors on Windows environments using cp932 encoding.","Prevent encoding-related crashes when scripts are executed through agents or redirected pipelines.","Standardize input and output encoding for cross-platform script compatibility."],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/nanase\/claude-skills\/blob\/b23836abbd3974fccd805579bfb31a9c18c69492\/plugins\/code\/skills\/script-encoding\/SKILL.md","source_commit":"b23836abbd3974fccd805579bfb31a9c18c69492","license":null,"version":null,"listing_approved_at":"2026-12-02","created_at":"2026-11-30T09:02:43.000000Z","updated_at":"2026-12-02T09:15:40.000000Z","seo_title":"Script Encoding - Ensure UTF-8 Encoding in Scripts","seo_description":"Learn how to configure scripts to use UTF-8 encoding explicitly, ensuring compatibility across different environments and avoiding locale-dependent encoding errors.","seo_keywords":["script encoding","utf-8 encoding","locale-independent scripts","python encoding","cross-platform script compatibility"]}}