[issue43576] python3.6.4 os.environ error when write chinese to file

2021-03-26 Thread Eryk Sun
Eryk Sun added the comment: > If you are lost with locale encodings, you can attempt to encode > everything in UTF-8 and enables the Python UTF-8 Mode: rushant is using Python 3.6. UTF-8 mode was added in 3.7, so it's not an option without first upgrading to 3.7. Also, it's important to note

[issue43576] python3.6.4 os.environ error when write chinese to file

2021-03-26 Thread STINNER Victor
STINNER Victor added the comment: Oh, I forgot to note that Windows is not affected by this issue, since Windows provides directly environment variables as Unicode, and so Python doesn't need to decode byte strings to read os.environ['a'] ;-) --

[issue43576] python3.6.4 os.environ error when write chinese to file

2021-03-26 Thread STINNER Victor
STINNER Victor added the comment: Python works as expected: the UTF-8 codec doesn't allow to encode surrogate characters. Surrogate characters are coming from os.environ['a'] because this environment variable contains bytes which cannot be decoded from the sys.getfilesystemencoding(). You

[issue43576] python3.6.4 os.environ error when write chinese to file

2021-03-26 Thread Eryk Sun
Eryk Sun added the comment: I think this is a locale configuration problem, in which the locale encoding doesn't match the terminal encoding. If so, it can be closed as not a bug. > export a="中文" In POSIX, the shell reads "中文" from the terminal as bytes encoded in the terminal encoding,

[issue43576] python3.6.4 os.environ error when write chinese to file

2021-03-26 Thread Terry J. Reedy
Terry J. Reedy added the comment: 3.6 only gets security patches. You or someone needs to show an unfixed bug in master. Your code runs for me on Windows, whereas you appear to be using *nix. Replacing job_name.encode() should have the same behavior. Do you see the same with

[issue43576] python3.6.4 os.environ error when write chinese to file

2021-03-20 Thread rushant
New submission from rushant <953779...@qq.com>: # -*- coding: utf-8 -*- import os job_name = os.environ['a'] print(job_name) print(isinstance(job_name, str)) print(type(job_name)) with open('name.txt', 'w', encoding='utf-8')as fw: fw.write(job_name) i have set environment param by : export