universal_newlines=True
. stdout=PIPE
locale.getpreferredencoding(False)
, utf-8 Windows. UnicodeDecodeError
.
utf-8, universal_newlines=True
:
from subprocess import Popen, PIPE
with Popen(r'C:\path\to\program.exe "arg 1" "arg 2"',
stdout=PIPE, stderr=PIPE) as p:
output, errors = p.communicate()
lines = output.decode('utf-8').splitlines()
str.encode("utf-8")
"utf-8".encode()
. .communicate()
, stdin=PIPE
, b'utf-8'
bytestring .
str.encode(encoding="utf-8", errors="ignore)
klass.method(**kwargs)
. .encode()
self
( ), TypeError
.
>>> str.encode("abc", encoding="utf-8", errors="ignore")
b'abc'
>>> "abc".encode(encoding="utf-8", errors="ignore")
b'abc'
klass.method(obj)
obj.method()
.