Python3 os.isatty() 方法
概述
os.isatty() 方法用于判斷如果文件描述符fd是打開的,同時(shí)與tty(-like)設(shè)備相連,則返回true, 否則False。
語法
isatty()方法語法格式如下:
os.isatty()
參數(shù)
- 無
返回值
如果文件描述符fd是打開的,同時(shí)與tty(-like)設(shè)備相連,則返回true, 否則False。
實(shí)例
以下實(shí)例演示了 isatty() 方法的使用:
#!/usr/bin/python3 import os, sys # 打開文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 寫入字符串 str = "This is w3cschool.cn site" os.write(fd,bytes(str, 'UTF-8')) # 使用 isatty() 查看文件 ret = os.isatty(fd) print ("返回值: ", ret) # 關(guān)閉文件 os.close( fd )
執(zhí)行以上程序輸出結(jié)果為:
返回值: False
更多建議: