Encoding problems occur when using Korean in Pycharm.

Asked 2 years ago, Updated 2 years ago, 97 views

Hello.

I'm studying Python.

Version 3.6 is used.

PiCham uses version 2017.3.3.

Encoding errors occur while practicing opening files.

f = open("test.txt", "w") f.write("Hangul Test")

f.close()

Traceback (most recent call last): File "/Volumes/Data/Source/Python/filetest/test.py", line 4, in f.write ("Hangul test") UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

If you explicitly insert open encoding='utf-8' above, it can be saved normally. f = open('test.txt', 'w', encoding='utf-8')

However, in the general console window (os terminal) instead of PaiCham,

If you use the same code as above, the storage will be normal.

$ python test.py (Saved normally and saved in Korean on file, python is the same version of Python in use by PyCham.)

As a result, I think it's a matter of setting up PiCham.

Even if you set all the File Encoding settings to utf-8 in the pie-cham setting

I keep getting the above error.

I don't need to set encoding='utf-8' every time explicitly opened.

I hope it works with utf-8 by default.

Is there any other way to set it up?

pycharm python python3 encoding utf-8

2022-09-22 14:37

1 Answers

What OS do you use first? I think it's either mac or linux, but...

In summary, it seems to be utf8 in the terminal, but it is set to ascii as the default encoding in pycharm.

At the terminal, please perform locale and check the encoding in the pycharm python shell with the code below.

import locale
print(locale.getpreferredencoding())

I think it's going to be ascii.

Pycharm seems to ignore LC_CTYPE value.

I don't know because I didn't use pycharm, but I think there is a way to explicitly put the configuration setting when performing pycharm.


2022-09-22 14:37

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.