вторник, 18 июля 2017 г.

isatty under pycharm

If you want to print something from python script only on real TTY (terminal), not in a file or redirected stream there is built in check for that: sys.stdout.isatty().
But it will return False for the pycharm console. To detect that script is executed under pycharm add or 'PYCHARM_HOSTED' in os.environ

is_direct_output = sys.stdout.isatty() or 'PYCHARM_HOSTED' in os.environ