Python的isatty()
方法如果檔描述符fd
打開並連接到tty(類似)設備,則返回True
,否則返回False
。
語法
以下是isatty()
方法的語法 -
os.isatty( fd )
參數
- fd - 這是需要檢查關聯的檔描述符。
返回值
- 如果檔描述符fd打開並連接到tty(類似)設備,則該方法返回
True
,否則返回False
。
示例
以下示例顯示了isatty()
方法的用法。
#!/usr/bin/python3
import os, sys
# Open a file
fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT )
# Write one string
line = "This is test"
b = line.encode()
os.write(fd, b)
# Now use isatty() to check the file.
ret = os.isatty(fd)
print ("Returned value is: ", ret)
# Close opened file
os.close( fd )
執行上面代碼後,將得到以下結果 -
Returned value is: False
上一篇:
Python os模組方法
下一篇:
Python異常處理