isatty() 함수를 사용하여 현재 스크립트가 터미널과 연결되어 있는지 확인할 수 있습니다. 예를 들어,
import sys
if sys.stdout.isatty():
print("Inside a terminal!")
else:
print("Piped output") 터미널에서 위의 내용을 실행하면 다음과 같이 출력됩니다.
"Inside a terminal!"
isatty() 함수를 사용하여 현재 스크립트가 터미널과 연결되어 있는지 확인할 수 있습니다. 예를 들어,
import sys
if sys.stdout.isatty():
print("Inside a terminal!")
else:
print("Piped output") 터미널에서 위의 내용을 실행하면 다음과 같이 출력됩니다.
"Inside a terminal!"