1. Opening a file
Successful executionError message
UnicodeEncodeError:'cp932'codec can't encode charactaer'\ xa5'in positition5: illegal multibyte sequenceApplicable source code
f = open ("Sample.txt", "w") f.write ( "Hello ¥ n") f.write ("Goodbye \ n") f.close ()
Supplemental information (FW/tool version etc.) If
f = open ("Sample.txt", "w") f.write ( "Hello") f.write ("Goodbye") f.close ()
\ n is not used, no error will occur.
How should we deal with it?
Answer # 1
You entered the wrong
\. Please enter a half-width backslash. Or copy and paste \.
Answer # 2
\may appear the same, but they are different characters.
Try copying the following code.
f = open ("Sample.txt", "w") f.write ( "Hello \ n") f.write ("Goodbye \ n") f.close ()
I think this will work.
Answer # 3
Do you want to use python2?
Add #-*-coding: utf-8-*-at the top of the program
(If you are creating a file with shift_jis, specify shift_jis instead of utf-8.
How to handle Japanese in Python
- python 3x - typeerror: 'method' object is not subscriptable
- python - you may need to restart the kernel to use updated packages error
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - emulator: dsound: could not initialize about the error message directsoundcapture
- android studio - unresolved reference comes out in kotlin
- mysql startup failed [error] innodb: the innodb_system data file 'ibdata1' must be writable
- django - oserror: [winerror 123] the file name, directory name, or volume label syntax is incorrect : '<frozen importlib_boot
- python - importerror: cannot import name md5 error cannot be resolved