How `[System.Console]::OutputEncoding/InputEncoding` with Python?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Under Powershell v5, Windows 8.1, Python 3. Why these fails and how to fix? [system.console]::InputEncoding = [System.Text.Encoding]::UTF8; [system.console]::OutputEncoding = [System.Text.Encoding]::UTF8; chcp; "import sys print(sys.stdout.encoding) print(sys.stdin.encoding) sys.stdout.write(sys.stdin.readline()) " | sc test.py -Encoding utf8; [char]0x0422+[char]0x0415+[char]0x0421+[char]0x0422+"`n" | py -3 test.py prints: 回答1: You are piping data into Python; at that point Python's stdin is no longer attached to a TTY (your console) and won