2012-11-14 4 views

답변

1

os.isatty을 사용한다. 파일 디스크립터 (fd)는 fileno 구성원으로 얻을 수 있습니다. 당신이 임의의 파일 취향을 지원하려면

>>> from os import isatty 
>>> isatty(sys.stdout.fileno()) 
True 

(예 StringIO)을, 당신은 모든 파일 좋아는하지 때문에 파일과 같은 연관된 FD가 있는지 여부를 확인해야 :

hasattr(f, "fileno") and isatty(f.fileno()) 
4

그래서 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') 
+0

흠 : 사용자가 파일 기술자 단말인지를 확인하는 os.isatty()를 사용()'] (http://docs.python.org/2 /library/stdtypes.html#file.isatty)? – Shep

관련 문제