Python 3 教程教程
Python3 os.isatty() 方法
Python3 os.isatty() 方法
Python3 os.isatty() 方法
概述
os.isatty() 方法用于判断如果文件描述符fd是打开的,同时与tty(-like)设备相连,则返回true, 否则False。
语法
isatty()方法语法格式如下:
os.isatty()
参数
- 无
返回值
如果文件描述符fd是打开的,同时与tty(-like)设备相连,则返回true, 否则False。
实例
以下实例演示了 isatty() 方法的使用:
#!/usr/bin/python3 import os, sys # 打开文件 fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) # 写入字符串 str = "This is verydoc.net site" os.write(fd,bytes(str, 'UTF-8')) # 使用 isatty() 查看文件 ret = os.isatty(fd) print ("返回值: ", ret) # 关闭文件 os.close( fd )
执行以上程序输出结果为:
返回值: False
Python3 os.isatty() 方法 |
---|
Python 3 教程
Python的3.0版本,常被称为Python 3000,或简称Py3k。相对于Python的早期版本,这是一个较大的升级。为了不带入过多的累赘,Python 3.0在设计的时候没有考虑向下兼容。