Python os.isatty() 方法
概述
os.isatty() 方法用於判斷如果檔描述符fd是打開的,同時與tty(-like)設備相連,則返回true, 否則False。
語法
isatty()方法語法格式如下:
os.isatty()
參數
- 無
返回值
如果檔描述符fd是打開的,同時與tty(-like)設備相連,則返回true, 否則False。
實例
以下實例演示了 isatty() 方法的使用:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打開檔 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 寫入字串 os.write(fd, "This is test") # 使用 isatty() 查看檔 ret = os.isatty(fd) print "返回值: ", ret # 關閉檔 os.close( fd )
執行以上程式輸出結果為:
返回值: False