描述
方法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 3 os.fstatvfs()用法及代碼示例
- Python 3 os.minor()用法及代碼示例
- Python 3 os.close()用法及代碼示例
- Python 3 os.unlink()用法及代碼示例
- Python 3 os.major()用法及代碼示例
- Python 3 os.rmdir()用法及代碼示例
- Python 3 os.fdopen()用法及代碼示例
- Python 3 os.fdatasync()用法及代碼示例
- Python 3 os.rename()用法及代碼示例
- Python 3 os.walk()用法及代碼示例
- Python 3 os.renames()用法及代碼示例
- Python 3 os.makedirs()用法及代碼示例
- Python 3 os.utime()用法及代碼示例
- Python 3 os.tcgetpgrp()用法及代碼示例
- Python 3 os.statvfs()用法及代碼示例
- Python 3 os.lchown()用法及代碼示例
- Python 3 os.mknod()用法及代碼示例
- Python 3 os.lstat()用法及代碼示例
- Python 3 os.tmpfile()用法及代碼示例
- Python 3 os.getcwd()用法及代碼示例
注:本文由純淨天空篩選整理自 Python 3 - os.isatty() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。