Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
This commit is contained in:
2017-09-25 13:17:26 -04:00
parent e65057c25f
commit ed76c4a4da
+19
View File
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
import sys
import os
def piped_in():
"""Returns piped input via stdin, else None."""
with sys.stdin as stdin:
# TTY is only way to detect if stdin contains data
if not stdin.isatty():
return stdin.read()
else:
return None
def is_interactive():
"""Returns if the current session is interactive or not."""
return bool(os.isatty(sys.stdout.fileno()))