Created
August 24, 2016 12:08
-
-
Save abakum/bf0f130e6499ff520eaf47a6e7085ae4 to your computer and use it in GitHub Desktop.
Bootstrap for ANSI python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python -i | |
# coding=cp1251 | |
# | |
from __future__ import unicode_literals | |
from __future__ import print_function | |
import os | |
import codecs | |
import sys | |
reload(sys) | |
print("if sys.stdout.isatty():") | |
if sys.stdout.isatty(): #wsl или py.exe или linux | |
sde=sys.stdout.encoding.lower() | |
if sde=="cp866": | |
sde="cp1251" | |
os.system("chcp %s>nul"%sde[2:]) | |
print(' os.system("chcp %s>nul"'%sde[2:]) | |
sys.stdout=codecs.getwriter(sde)(sys.stdout) | |
print(' sys.stdout=codecs.getwriter("%s")(sys.stdout)'%sde) | |
print(' sys.setdefaultencoding("%s")'%sde) | |
else: #bat или mingw или mintty | |
sde="cp1251" | |
print("else:") | |
print(' sys.setdefaultencoding("%s")'%sde) | |
if "LANG" in os.environ: #mingw или mintty -o Locale=ru_RU -o Charset=UTF-8 или mintty -o Locale=ru_RU -o Charset=CP1251 | |
sse=os.environ["LANG"].split(".")[1].lower() | |
if sse!=sde: | |
sys.stdout=codecs.getwriter(sse)(sys.stdout) | |
print(' sys.stdout=codecs.getwriter("%s")(sys.stdout)'%sse) | |
sys.setdefaultencoding(sde) | |
import platform | |
print(platform.uname()) | |
s=platform.python_compiler() | |
print(platform._sys_version_cache.keys()[0], sys.executable) | |
... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment