What to do if you are addicted to Windows character code

Introduction

An error occurred while processing a path containing Japanese on Windows. UnicodeDecodeError occurs even though the character code is Shift-JIS.

Wasn't Windows Shift-JIS?

How to respond

When I looked it up, it said that "Windows is CP932, which is an extension of Shift-JIS." So, when I specified the character code to CP932, it worked smoothly.

Sample code

cp932_test.py


# -*- coding: utf-8 -*-

s = '①②③④'	# Shift-Characters in CP932, not in JIS
su = unicode(s, 'utf-8')
print su.encode('cp932')
print su.encode('shift-jis')    #Get UnicodeEncodeError

in conclusion

Recognize that Shift-JIS in Windows is "CP932". Otherwise, you will be addicted to it.

Recommended Posts

What to do if you are addicted to Windows character code
What to do if you can't pip install mysqlclient
No module named What to do if you get'libs.resources'
ModuleNotFoundError: No module What to do if you get'tensorflow.contrib'
What to do if yum breaks
What to do if the Microsoft Store opens even if you run python on Windows
What to do if you get "coverage unknown" in Coveralls
What to do if you can't sort files with subscripts
What to do if Python IntelliSense is not displayed in VS Code on Windows
What to do if you can't log in as root
What to do if you can't use WiFi on Linux
ImportError: No module What to do when you are told
What to do if you lose your EC2 key pair
What to do if Python doesn't work on Git for Windows
What to do if you can't install pyaudio with pip #Python
What to do if you get a minus zero in Python
What to do if you get a UnicodeDecodeError with pip install
What to do if you can't build your project with Maven
What to do if PyAudio cannot be installed on Python 3.7, 3.8, 3.9 on Windows
What to do if you can't use the trash in Lubuntu 18.04.
Let's summarize what you want to do.
What to do if you can't find well with grep's -f option
What to do if you can't find PDO in Laravel or CakePHP
What to do if you couldn't send an email to Yahoo with Python.
What to do if you can't use scikit grid search in Python
What to do if you forget your login password on Manjaro Linux
What to do if you get lost in file reference with FileNotFoundError
What to do if you get angry in TensorFlow v2 without attribute'app'
What to do if you get stuck during Anaconda installation on Linux
What to do if the Chainer (Windows) sample mnist terminates with WinError 183.
What to do if you get a TypeError with numpy min, max
What to do if you get an error when trying to load mnist
What to do if you can't install with pip in babun environment
What to do if you get Could not fetch URL 443 with pip
What to do if you get an error when installing Dlib (Ubuntu)
What to do if pipreqs results in UnicodeDecodeError
Note: What to do if pip install fails
What to do if mod_fcgid cannot resolve UnicodeEncodeError
What to do if rails s doesn't work
What to do if you should have set an ssh key but are prompted for a password
What to do if pip cannot be installed
What to do if atom autocomplete-python doesn't work
What to do if Docker-sync suddenly stops working
What to do if "amazon-linux-extras" → "No module named amazon_linux_extras"
What to do if you get a "No versions found" error in pipenv
What to do if you get angry with swapon failed: Operation not permitted
What to do if you get an error when installing python with pyenv
What to do if you get "Python not configured." Using PyDev in Eclipse
What to do when you want to receive files from a Windows client remotely
What to do if you are told "Import Error: cannot import name'HTTPSHandler'" when building a virtual environment using virtualenv
What to do if SciPy installation fails on CentOS
Links to do what you want with Sublime Text
What to do if a UnicodeDecodeError occurs in pip
What to do if pip install fails to install dependent libraries
What to do if sys / cdefs.h does not exist
What to do if pyenv is not enabled (zsh)
What to do when you can't bind CaboCha to Python
What to do if you get an "unknown service" error from your gRPC server
What to do if you get an OpenSSL error when installing Python 2 with pyenv
What to do if you get `No kernel for language python found` in Hydrogen
What to do if you get a memory error when converting from PySparkDataFrame to PandasDataFrame