19 lines
551 B
Python
19 lines
551 B
Python
"""專案共用小工具:主控台輸出編碼處理。"""
|
|
|
|
import sys
|
|
|
|
|
|
def ensure_utf8_console() -> None:
|
|
"""將 stdout/stderr 切為 UTF-8,避免在 Big5/cp950 主控台輸出中文時崩潰。"""
|
|
for stream in (sys.stdout, sys.stderr):
|
|
reconfigure = getattr(stream, "reconfigure", None)
|
|
if reconfigure is not None:
|
|
try:
|
|
reconfigure(encoding="utf-8")
|
|
except Exception:
|
|
pass
|
|
|
|
|
|
if __name__ == "__main__":
|
|
ensure_utf8_console()
|
|
print("console utf-8 ready") |