파이썬 프로세스의 출력이 파일에 기록되는지 확인하는 방법이 있습니까? 나는 다음과 같은 것을 할 수 있기를 바란다.파일이 터미널에 기록되는지 확인하는 방법은 무엇입니까?
if is_writing_to_terminal:
sys.stdout.write('one thing')
else:
sys.stdout.write('another thing')
파이썬 프로세스의 출력이 파일에 기록되는지 확인하는 방법이 있습니까? 나는 다음과 같은 것을 할 수 있기를 바란다.파일이 터미널에 기록되는지 확인하는 방법은 무엇입니까?
if is_writing_to_terminal:
sys.stdout.write('one thing')
else:
sys.stdout.write('another thing')
os.isatty
을 사용한다. 파일 디스크립터 (fd)는 fileno
구성원으로 얻을 수 있습니다. 당신이 임의의 파일 취향을 지원하려면
>>> from os import isatty
>>> isatty(sys.stdout.fileno())
True
(예 StringIO
)을, 당신은 모든 파일 좋아는하지 때문에 파일과 같은 연관된 FD가 있는지 여부를 확인해야 :
hasattr(f, "fileno") and isatty(f.fileno())
그래서 os.isatty '사이의 차이 (sys.stdout.fileno())'가 있고 [`sys.stdout.isatty,
if os.isatty(sys.stdout.fileno()):
sys.stdout.write('one thing')
else:
sys.stdout.write('another thing')
흠 : 사용자가 파일 기술자 단말인지를 확인하는
os.isatty()
를 사용()'] (http://docs.python.org/2 /library/stdtypes.html#file.isatty)? – Shep