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 t
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'] ;-)
--
_
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
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, whic
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 job_name="中文"
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